directed-graph-typed 1.48.0 → 1.49.0
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/base/index.d.ts +1 -0
- package/dist/data-structures/base/index.js +17 -0
- package/dist/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/data-structures/base/iterable-base.js +312 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +28 -19
- package/dist/data-structures/binary-tree/avl-tree.js +22 -11
- package/dist/data-structures/binary-tree/binary-tree.d.ts +158 -152
- package/dist/data-structures/binary-tree/binary-tree.js +241 -215
- package/dist/data-structures/binary-tree/bst.d.ts +64 -48
- package/dist/data-structures/binary-tree/bst.js +94 -65
- package/dist/data-structures/binary-tree/rb-tree.d.ts +39 -39
- package/dist/data-structures/binary-tree/rb-tree.js +42 -49
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +60 -34
- package/dist/data-structures/binary-tree/tree-multimap.js +59 -27
- package/dist/data-structures/graph/abstract-graph.d.ts +92 -53
- package/dist/data-structures/graph/abstract-graph.js +130 -103
- package/dist/data-structures/graph/directed-graph.d.ts +70 -52
- package/dist/data-structures/graph/directed-graph.js +111 -65
- package/dist/data-structures/graph/map-graph.d.ts +5 -5
- package/dist/data-structures/graph/map-graph.js +8 -8
- package/dist/data-structures/graph/undirected-graph.d.ts +51 -32
- package/dist/data-structures/graph/undirected-graph.js +117 -54
- package/dist/data-structures/hash/hash-map.d.ts +160 -44
- package/dist/data-structures/hash/hash-map.js +314 -82
- package/dist/data-structures/heap/heap.d.ts +50 -7
- package/dist/data-structures/heap/heap.js +60 -30
- package/dist/data-structures/index.d.ts +1 -0
- package/dist/data-structures/index.js +1 -0
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +42 -55
- package/dist/data-structures/linked-list/doubly-linked-list.js +50 -77
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +36 -55
- package/dist/data-structures/linked-list/singly-linked-list.js +44 -77
- package/dist/data-structures/queue/deque.d.ts +35 -167
- package/dist/data-structures/queue/deque.js +43 -249
- package/dist/data-structures/queue/queue.d.ts +49 -48
- package/dist/data-structures/queue/queue.js +69 -82
- package/dist/data-structures/stack/stack.d.ts +43 -10
- package/dist/data-structures/stack/stack.js +50 -31
- package/dist/data-structures/trie/trie.d.ts +41 -6
- package/dist/data-structures/trie/trie.js +53 -32
- package/dist/interfaces/binary-tree.d.ts +6 -6
- package/dist/types/common.d.ts +11 -8
- package/dist/types/common.js +6 -1
- package/dist/types/data-structures/base/base.d.ts +5 -0
- package/dist/types/data-structures/base/base.js +2 -0
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/index.js +17 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/types/data-structures/hash/hash-map.d.ts +4 -0
- package/dist/types/data-structures/index.d.ts +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-base.ts +329 -0
- package/src/data-structures/binary-tree/avl-tree.ts +37 -25
- package/src/data-structures/binary-tree/binary-tree.ts +336 -296
- package/src/data-structures/binary-tree/bst.ts +135 -89
- package/src/data-structures/binary-tree/rb-tree.ts +60 -69
- package/src/data-structures/binary-tree/tree-multimap.ts +86 -49
- package/src/data-structures/graph/abstract-graph.ts +136 -104
- package/src/data-structures/graph/directed-graph.ts +114 -65
- package/src/data-structures/graph/map-graph.ts +8 -8
- package/src/data-structures/graph/undirected-graph.ts +124 -56
- package/src/data-structures/hash/hash-map.ts +335 -84
- package/src/data-structures/heap/heap.ts +63 -36
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +54 -83
- package/src/data-structures/linked-list/singly-linked-list.ts +49 -84
- package/src/data-structures/queue/deque.ts +43 -275
- package/src/data-structures/queue/queue.ts +71 -86
- package/src/data-structures/stack/stack.ts +53 -34
- package/src/data-structures/trie/trie.ts +58 -35
- package/src/interfaces/binary-tree.ts +5 -6
- package/src/types/common.ts +11 -8
- package/src/types/data-structures/base/base.ts +6 -0
- package/src/types/data-structures/base/index.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
- package/src/types/data-structures/hash/hash-map.ts +2 -0
- package/src/types/data-structures/heap/heap.ts +1 -1
- package/src/types/data-structures/index.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SinglyLinkedList = exports.SinglyLinkedListNode = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
4
5
|
/**
|
|
5
6
|
* data-structure-typed
|
|
6
7
|
*
|
|
@@ -20,11 +21,12 @@ class SinglyLinkedListNode {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
exports.SinglyLinkedListNode = SinglyLinkedListNode;
|
|
23
|
-
class SinglyLinkedList {
|
|
24
|
+
class SinglyLinkedList extends base_1.IterableElementBase {
|
|
24
25
|
/**
|
|
25
26
|
* The constructor initializes the linked list with an empty head, tail, and length.
|
|
26
27
|
*/
|
|
27
28
|
constructor(elements) {
|
|
29
|
+
super();
|
|
28
30
|
this._head = undefined;
|
|
29
31
|
this._tail = undefined;
|
|
30
32
|
this._length = 0;
|
|
@@ -142,12 +144,12 @@ class SinglyLinkedList {
|
|
|
142
144
|
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
143
145
|
* Space Complexity: O(1) - Constant space.
|
|
144
146
|
*
|
|
145
|
-
* The `
|
|
147
|
+
* The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
146
148
|
* pointers accordingly.
|
|
147
149
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
148
150
|
* the linked list is empty, it returns `undefined`.
|
|
149
151
|
*/
|
|
150
|
-
|
|
152
|
+
pollLast() {
|
|
151
153
|
return this.pop();
|
|
152
154
|
}
|
|
153
155
|
/**
|
|
@@ -177,10 +179,10 @@ class SinglyLinkedList {
|
|
|
177
179
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
178
180
|
* Space Complexity: O(1) - Constant space.
|
|
179
181
|
*
|
|
180
|
-
* The `
|
|
182
|
+
* The `pollFirst()` function removes and returns the value of the first node in a linked list.
|
|
181
183
|
* @returns The value of the node that is being removed from the beginning of the linked list.
|
|
182
184
|
*/
|
|
183
|
-
|
|
185
|
+
pollFirst() {
|
|
184
186
|
return this.shift();
|
|
185
187
|
}
|
|
186
188
|
/**
|
|
@@ -609,54 +611,31 @@ class SinglyLinkedList {
|
|
|
609
611
|
return count;
|
|
610
612
|
}
|
|
611
613
|
/**
|
|
612
|
-
*
|
|
613
|
-
*/
|
|
614
|
-
*[Symbol.iterator]() {
|
|
615
|
-
let current = this.head;
|
|
616
|
-
while (current) {
|
|
617
|
-
yield current.value;
|
|
618
|
-
current = current.next;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
623
|
-
* Space Complexity: O(1)
|
|
624
|
-
*/
|
|
625
|
-
/**
|
|
626
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
627
|
-
* Space Complexity: O(1)
|
|
628
|
-
*
|
|
629
|
-
* The `forEach` function iterates over each element in a linked list and applies a callback function to each element.
|
|
630
|
-
* @param callback - The callback parameter is a function that takes two arguments: value and index. The value argument
|
|
631
|
-
* represents the value of the current node in the linked list, and the index argument represents the index of the
|
|
632
|
-
* current node in the linked list.
|
|
633
|
-
*/
|
|
634
|
-
forEach(callback) {
|
|
635
|
-
let index = 0;
|
|
636
|
-
for (const el of this) {
|
|
637
|
-
callback(el, index, this);
|
|
638
|
-
index++;
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
/**
|
|
642
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
614
|
+
* Time Complexity: O(n)
|
|
643
615
|
* Space Complexity: O(n)
|
|
644
616
|
*/
|
|
645
617
|
/**
|
|
646
|
-
* Time Complexity: O(n)
|
|
618
|
+
* Time Complexity: O(n)
|
|
647
619
|
* Space Complexity: O(n)
|
|
648
620
|
*
|
|
649
|
-
* The `filter` function
|
|
650
|
-
*
|
|
651
|
-
*
|
|
652
|
-
*
|
|
653
|
-
*
|
|
654
|
-
|
|
655
|
-
|
|
621
|
+
* The `filter` function creates a new SinglyLinkedList by iterating over the elements of the current
|
|
622
|
+
* list and applying a callback function to each element to determine if it should be included in the
|
|
623
|
+
* filtered list.
|
|
624
|
+
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
625
|
+
* list. It takes three arguments: the current element, the index of the current element, and the
|
|
626
|
+
* list itself. The callback function should return a boolean value indicating whether the current
|
|
627
|
+
* element should be included in the filtered list or not
|
|
628
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
629
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
630
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
631
|
+
* @returns The `filter` method is returning a new `SinglyLinkedList` object that contains the
|
|
632
|
+
* elements that pass the filter condition specified by the `callback` function.
|
|
633
|
+
*/
|
|
634
|
+
filter(callback, thisArg) {
|
|
656
635
|
const filteredList = new SinglyLinkedList();
|
|
657
636
|
let index = 0;
|
|
658
637
|
for (const current of this) {
|
|
659
|
-
if (callback(current, index, this)) {
|
|
638
|
+
if (callback.call(thisArg, current, index, this)) {
|
|
660
639
|
filteredList.push(current);
|
|
661
640
|
}
|
|
662
641
|
index++;
|
|
@@ -668,21 +647,24 @@ class SinglyLinkedList {
|
|
|
668
647
|
* Space Complexity: O(n)
|
|
669
648
|
*/
|
|
670
649
|
/**
|
|
671
|
-
* Time Complexity: O(n)
|
|
650
|
+
* Time Complexity: O(n)
|
|
672
651
|
* Space Complexity: O(n)
|
|
673
652
|
*
|
|
674
|
-
* The `map` function
|
|
675
|
-
*
|
|
676
|
-
* @param callback - The callback parameter is a function that
|
|
677
|
-
* the
|
|
678
|
-
*
|
|
679
|
-
*
|
|
680
|
-
|
|
681
|
-
|
|
653
|
+
* The `map` function creates a new SinglyLinkedList by applying a callback function to each element
|
|
654
|
+
* of the original list.
|
|
655
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
656
|
+
* the linked list. It takes three arguments:
|
|
657
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
658
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
659
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
660
|
+
* @returns The `map` function is returning a new `SinglyLinkedList` object that contains the results
|
|
661
|
+
* of applying the provided `callback` function to each element in the original list.
|
|
662
|
+
*/
|
|
663
|
+
map(callback, thisArg) {
|
|
682
664
|
const mappedList = new SinglyLinkedList();
|
|
683
665
|
let index = 0;
|
|
684
666
|
for (const current of this) {
|
|
685
|
-
mappedList.push(callback(current, index, this));
|
|
667
|
+
mappedList.push(callback.call(thisArg, current, index, this));
|
|
686
668
|
index++;
|
|
687
669
|
}
|
|
688
670
|
return mappedList;
|
|
@@ -691,30 +673,15 @@ class SinglyLinkedList {
|
|
|
691
673
|
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
692
674
|
* Space Complexity: O(n)
|
|
693
675
|
*/
|
|
694
|
-
/**
|
|
695
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
696
|
-
* Space Complexity: O(n)
|
|
697
|
-
*
|
|
698
|
-
* The `reduce` function iterates over a linked list and applies a callback function to each element, accumulating a
|
|
699
|
-
* single value.
|
|
700
|
-
* @param callback - The `callback` parameter is a function that takes two arguments: `accumulator` and `value`. It is
|
|
701
|
-
* used to perform a specific operation on each element of the linked list.
|
|
702
|
-
* @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It is the starting
|
|
703
|
-
* point for the reduction operation.
|
|
704
|
-
* @returns The `reduce` method is returning the final value of the accumulator after iterating through all the
|
|
705
|
-
* elements in the linked list.
|
|
706
|
-
*/
|
|
707
|
-
reduce(callback, initialValue) {
|
|
708
|
-
let accumulator = initialValue;
|
|
709
|
-
let index = 0;
|
|
710
|
-
for (const current of this) {
|
|
711
|
-
accumulator = callback(accumulator, current, index, this);
|
|
712
|
-
index++;
|
|
713
|
-
}
|
|
714
|
-
return accumulator;
|
|
715
|
-
}
|
|
716
676
|
print() {
|
|
717
677
|
console.log([...this]);
|
|
718
678
|
}
|
|
679
|
+
*_getIterator() {
|
|
680
|
+
let current = this.head;
|
|
681
|
+
while (current) {
|
|
682
|
+
yield current.value;
|
|
683
|
+
current = current.next;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
719
686
|
}
|
|
720
687
|
exports.SinglyLinkedList = SinglyLinkedList;
|
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import { IterableWithSizeOrLength } from "../../types";
|
|
8
|
+
import { ElementCallback, IterableWithSizeOrLength } from "../../types";
|
|
9
|
+
import { IterableElementBase } from "../base";
|
|
9
10
|
/**
|
|
10
11
|
* Deque can provide random access with O(1) time complexity
|
|
11
12
|
* Deque is usually more compact and efficient in memory usage because it does not require additional space to store pointers.
|
|
12
13
|
* Deque may experience performance jitter, but DoublyLinkedList will not
|
|
13
14
|
* 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
|
*/
|
|
15
|
-
export declare class Deque<E> {
|
|
16
|
+
export declare class Deque<E> extends IterableElementBase<E> {
|
|
16
17
|
protected _bucketFirst: number;
|
|
17
18
|
protected _firstInBucket: number;
|
|
18
19
|
protected _bucketLast: number;
|
|
@@ -66,10 +67,10 @@ export declare class Deque<E> {
|
|
|
66
67
|
* Time Complexity: O(1) - Removes the last element.
|
|
67
68
|
* Space Complexity: O(1) - Operates in-place.
|
|
68
69
|
*
|
|
69
|
-
* The function "
|
|
70
|
+
* The function "pollLast" removes and returns the last element of an array.
|
|
70
71
|
* @returns The last element of the array is being returned.
|
|
71
72
|
*/
|
|
72
|
-
|
|
73
|
+
pollLast(): E | undefined;
|
|
73
74
|
/**
|
|
74
75
|
* Time Complexity: O(1).
|
|
75
76
|
* Space Complexity: O(n) - Due to potential resizing.
|
|
@@ -83,11 +84,11 @@ export declare class Deque<E> {
|
|
|
83
84
|
* Time Complexity: O(1) - Removes the first element.
|
|
84
85
|
* Space Complexity: O(1) - In-place operation.
|
|
85
86
|
*
|
|
86
|
-
* The function "
|
|
87
|
-
* @returns The method `
|
|
87
|
+
* The function "pollFirst" removes and returns the first element of an array.
|
|
88
|
+
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
88
89
|
* from the beginning. If the array is empty, it will return `undefined`.
|
|
89
90
|
*/
|
|
90
|
-
|
|
91
|
+
pollFirst(): E | undefined;
|
|
91
92
|
/**
|
|
92
93
|
* The clear() function resets the state of the object by initializing all variables to their default
|
|
93
94
|
* values.
|
|
@@ -354,32 +355,6 @@ export declare class Deque<E> {
|
|
|
354
355
|
* @returns The `toArray()` method is returning an array of elements of type `E`.
|
|
355
356
|
*/
|
|
356
357
|
toArray(): E[];
|
|
357
|
-
/**
|
|
358
|
-
* Time Complexity: O(n)
|
|
359
|
-
* Space Complexity: O(1)
|
|
360
|
-
*/
|
|
361
|
-
/**
|
|
362
|
-
* Time Complexity: O(n)
|
|
363
|
-
* Space Complexity: O(1)
|
|
364
|
-
*
|
|
365
|
-
* The above function is an implementation of the iterator protocol in TypeScript, allowing the
|
|
366
|
-
* object to be iterated over using a for...of loop.
|
|
367
|
-
*/
|
|
368
|
-
[Symbol.iterator](): Generator<E, void, unknown>;
|
|
369
|
-
/**
|
|
370
|
-
* Time Complexity: O(n)
|
|
371
|
-
* Space Complexity: O(1)
|
|
372
|
-
*/
|
|
373
|
-
/**
|
|
374
|
-
* Time Complexity: O(n)
|
|
375
|
-
* Space Complexity: O(1)
|
|
376
|
-
*
|
|
377
|
-
* The `forEach` function iterates over each element in a deque and applies a callback function to
|
|
378
|
-
* each element.
|
|
379
|
-
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
380
|
-
* deque. It takes three parameters:
|
|
381
|
-
*/
|
|
382
|
-
forEach(callback: (element: E, index: number, deque: this) => void): void;
|
|
383
358
|
/**
|
|
384
359
|
* Time Complexity: O(n)
|
|
385
360
|
* Space Complexity: O(n)
|
|
@@ -388,14 +363,19 @@ export declare class Deque<E> {
|
|
|
388
363
|
* Time Complexity: O(n)
|
|
389
364
|
* Space Complexity: O(n)
|
|
390
365
|
*
|
|
391
|
-
* The `filter` function creates a new deque containing
|
|
392
|
-
* predicate function.
|
|
393
|
-
* @param predicate - The `predicate` parameter is a function that takes three arguments:
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
366
|
+
* The `filter` function creates a new deque containing elements from the original deque that satisfy
|
|
367
|
+
* a given predicate function.
|
|
368
|
+
* @param predicate - The `predicate` parameter is a callback function that takes three arguments:
|
|
369
|
+
* the current element being iterated over, the index of the current element, and the deque itself.
|
|
370
|
+
* It should return a boolean value indicating whether the element should be included in the filtered
|
|
371
|
+
* deque or not.
|
|
372
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
373
|
+
* to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
|
|
374
|
+
* passed as the `this` value to the `predicate` function. If `thisArg` is
|
|
375
|
+
* @returns The `filter` method is returning a new `Deque` object that contains the elements that
|
|
376
|
+
* satisfy the given predicate function.
|
|
397
377
|
*/
|
|
398
|
-
filter(predicate:
|
|
378
|
+
filter(predicate: ElementCallback<E, boolean>, thisArg?: any): Deque<E>;
|
|
399
379
|
/**
|
|
400
380
|
* Time Complexity: O(n)
|
|
401
381
|
* Space Complexity: O(n)
|
|
@@ -404,31 +384,29 @@ export declare class Deque<E> {
|
|
|
404
384
|
* Time Complexity: O(n)
|
|
405
385
|
* Space Complexity: O(n)
|
|
406
386
|
*
|
|
407
|
-
* The `map` function
|
|
408
|
-
*
|
|
409
|
-
* @param callback - The `callback` parameter is a function that
|
|
410
|
-
*
|
|
387
|
+
* The `map` function creates a new Deque by applying a callback function to each element of the
|
|
388
|
+
* original Deque.
|
|
389
|
+
* @param callback - The `callback` parameter is a function that will be called for each element in
|
|
390
|
+
* the deque. It takes three arguments:
|
|
391
|
+
* @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
|
|
392
|
+
* to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
|
|
393
|
+
* passed as the `this` value to the `callback` function. If `thisArg` is
|
|
394
|
+
* @returns a new Deque object with the mapped values.
|
|
411
395
|
*/
|
|
412
|
-
map<T>(callback:
|
|
396
|
+
map<T>(callback: ElementCallback<E, T>, thisArg?: any): Deque<T>;
|
|
413
397
|
/**
|
|
414
398
|
* Time Complexity: O(n)
|
|
415
|
-
* Space Complexity: O(
|
|
399
|
+
* Space Complexity: O(n)
|
|
416
400
|
*/
|
|
401
|
+
print(): void;
|
|
417
402
|
/**
|
|
418
403
|
* Time Complexity: O(n)
|
|
419
404
|
* Space Complexity: O(1)
|
|
420
405
|
*
|
|
421
|
-
* The
|
|
422
|
-
*
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
* is the value that will be passed as the first argument to the `callback` function when reducing
|
|
426
|
-
* the elements of the deque.
|
|
427
|
-
* @returns the final value of the accumulator after iterating over all elements in the deque and
|
|
428
|
-
* applying the callback function to each element.
|
|
429
|
-
*/
|
|
430
|
-
reduce<T>(callback: (accumulator: T, element: E, index: number, deque: this) => T, initialValue: T): T;
|
|
431
|
-
print(): void;
|
|
406
|
+
* The above function is an implementation of the iterator protocol in TypeScript, allowing the
|
|
407
|
+
* object to be iterated over using a for...of loop.
|
|
408
|
+
*/
|
|
409
|
+
protected _getIterator(): Generator<E, void, unknown>;
|
|
432
410
|
/**
|
|
433
411
|
* Time Complexity: O(n)
|
|
434
412
|
* Space Complexity: O(n)
|
|
@@ -461,113 +439,3 @@ export declare class Deque<E> {
|
|
|
461
439
|
indexInBucket: number;
|
|
462
440
|
};
|
|
463
441
|
}
|
|
464
|
-
export declare class ObjectDeque<E = number> {
|
|
465
|
-
constructor(capacity?: number);
|
|
466
|
-
protected _nodes: {
|
|
467
|
-
[key: number]: E;
|
|
468
|
-
};
|
|
469
|
-
get nodes(): {
|
|
470
|
-
[p: number]: E;
|
|
471
|
-
};
|
|
472
|
-
protected _capacity: number;
|
|
473
|
-
get capacity(): number;
|
|
474
|
-
protected _first: number;
|
|
475
|
-
get first(): number;
|
|
476
|
-
protected _last: number;
|
|
477
|
-
get last(): number;
|
|
478
|
-
protected _size: number;
|
|
479
|
-
get size(): number;
|
|
480
|
-
/**
|
|
481
|
-
* Time Complexity: O(1)
|
|
482
|
-
* Space Complexity: O(1)
|
|
483
|
-
*/
|
|
484
|
-
/**
|
|
485
|
-
* Time Complexity: O(1)
|
|
486
|
-
* Space Complexity: O(1)
|
|
487
|
-
*
|
|
488
|
-
* The "addFirst" function adds an element to the beginning of an array-like data structure.
|
|
489
|
-
* @param {E} element - The `element` parameter represents the element that you want to add to the beginning of the data
|
|
490
|
-
* structure.
|
|
491
|
-
*/
|
|
492
|
-
addFirst(element: E): void;
|
|
493
|
-
/**
|
|
494
|
-
* Time Complexity: O(1)
|
|
495
|
-
* Space Complexity: O(1)
|
|
496
|
-
*/
|
|
497
|
-
/**
|
|
498
|
-
* Time Complexity: O(1)
|
|
499
|
-
* Space Complexity: O(1)
|
|
500
|
-
*
|
|
501
|
-
* The addLast function adds an element to the end of an array-like data structure.
|
|
502
|
-
* @param {E} element - The `element` parameter represents the element that you want to add to the end of the data structure.
|
|
503
|
-
*/
|
|
504
|
-
addLast(element: E): void;
|
|
505
|
-
/**
|
|
506
|
-
* Time Complexity: O(1)
|
|
507
|
-
* Space Complexity: O(1)
|
|
508
|
-
*/
|
|
509
|
-
/**
|
|
510
|
-
* Time Complexity: O(1)
|
|
511
|
-
* Space Complexity: O(1)
|
|
512
|
-
*
|
|
513
|
-
* The function `popFirst()` removes and returns the first element in a data structure.
|
|
514
|
-
* @returns The element of the first element in the data structure.
|
|
515
|
-
*/
|
|
516
|
-
popFirst(): E | undefined;
|
|
517
|
-
/**
|
|
518
|
-
* Time Complexity: O(1)
|
|
519
|
-
* Space Complexity: O(1)
|
|
520
|
-
*/
|
|
521
|
-
/**
|
|
522
|
-
* Time Complexity: O(1)
|
|
523
|
-
* Space Complexity: O(1)
|
|
524
|
-
*
|
|
525
|
-
* The `getFirst` function returns the first element in an array-like data structure if it exists.
|
|
526
|
-
* @returns The element at the first position of the `_nodes` array.
|
|
527
|
-
*/
|
|
528
|
-
getFirst(): E | undefined;
|
|
529
|
-
/**
|
|
530
|
-
* Time Complexity: O(1)
|
|
531
|
-
* Space Complexity: O(1)
|
|
532
|
-
*/
|
|
533
|
-
/**
|
|
534
|
-
* Time Complexity: O(1)
|
|
535
|
-
* Space Complexity: O(1)
|
|
536
|
-
*
|
|
537
|
-
* The `popLast()` function removes and returns the last element in a data structure.
|
|
538
|
-
* @returns The element that was removed from the data structure.
|
|
539
|
-
*/
|
|
540
|
-
popLast(): E | undefined;
|
|
541
|
-
/**
|
|
542
|
-
* Time Complexity: O(1)
|
|
543
|
-
* Space Complexity: O(1)
|
|
544
|
-
*/
|
|
545
|
-
/**
|
|
546
|
-
* Time Complexity: O(1)
|
|
547
|
-
* Space Complexity: O(1)
|
|
548
|
-
*
|
|
549
|
-
* The `getLast()` function returns the last element in an array-like data structure.
|
|
550
|
-
* @returns The last element in the array "_nodes" is being returned.
|
|
551
|
-
*/
|
|
552
|
-
getLast(): E | undefined;
|
|
553
|
-
/**
|
|
554
|
-
* Time Complexity: O(1)
|
|
555
|
-
* Space Complexity: O(1)
|
|
556
|
-
*/
|
|
557
|
-
/**
|
|
558
|
-
* Time Complexity: O(1)
|
|
559
|
-
* Space Complexity: O(1)
|
|
560
|
-
*
|
|
561
|
-
* The get function returns the element at the specified index in an array-like data structure.
|
|
562
|
-
* @param {number} index - The index parameter is a number that represents the position of the element you want to
|
|
563
|
-
* retrieve from the array.
|
|
564
|
-
* @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
|
|
565
|
-
* index, `undefined` is returned.
|
|
566
|
-
*/
|
|
567
|
-
get(index: number): NonNullable<E> | undefined;
|
|
568
|
-
/**
|
|
569
|
-
* The function checks if the size of a data structure is less than or equal to zero.
|
|
570
|
-
* @returns The method is returning a boolean element indicating whether the size of the object is less than or equal to 0.
|
|
571
|
-
*/
|
|
572
|
-
isEmpty(): boolean;
|
|
573
|
-
}
|