data-structure-typed 1.50.1 → 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 +2 -1
- package/README.md +30 -28
- 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 -161
- package/dist/cjs/data-structures/base/iterable-base.d.ts +120 -9
- package/dist/cjs/data-structures/base/iterable-base.js +143 -7
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +72 -47
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +101 -72
- 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 +244 -199
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +92 -79
- package/dist/cjs/data-structures/binary-tree/bst.js +68 -76
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +127 -57
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +152 -99
- 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 +72 -58
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +102 -85
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -189
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +73 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +131 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/cjs/data-structures/graph/map-graph.js +14 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +76 -7
- package/dist/cjs/data-structures/graph/undirected-graph.js +151 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +254 -28
- package/dist/cjs/data-structures/hash/hash-map.js +347 -78
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +95 -25
- package/dist/cjs/data-structures/heap/heap.js +95 -26
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +141 -77
- 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 +154 -106
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +164 -115
- 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 +63 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/cjs/data-structures/matrix/matrix.js +50 -11
- package/dist/cjs/data-structures/matrix/matrix.js.map +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 +139 -35
- package/dist/cjs/data-structures/queue/deque.js +200 -62
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +103 -49
- package/dist/cjs/data-structures/queue/queue.js +111 -49
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +51 -21
- package/dist/cjs/data-structures/stack/stack.js +58 -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 +135 -34
- package/dist/cjs/data-structures/trie/trie.js +153 -33
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/cjs/types/utils/utils.d.ts +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +120 -9
- package/dist/mjs/data-structures/base/iterable-base.js +143 -7
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +72 -47
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +102 -73
- 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 +244 -199
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +92 -79
- package/dist/mjs/data-structures/binary-tree/bst.js +68 -76
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +127 -57
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +153 -100
- 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 +72 -58
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +102 -86
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -78
- package/dist/mjs/data-structures/graph/abstract-graph.js +3 -188
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +73 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +131 -0
- package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/mjs/data-structures/graph/map-graph.js +14 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +76 -7
- package/dist/mjs/data-structures/graph/undirected-graph.js +152 -19
- package/dist/mjs/data-structures/hash/hash-map.d.ts +254 -28
- package/dist/mjs/data-structures/hash/hash-map.js +353 -84
- package/dist/mjs/data-structures/heap/heap.d.ts +95 -25
- package/dist/mjs/data-structures/heap/heap.js +95 -26
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +144 -80
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +154 -106
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +166 -117
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/mjs/data-structures/matrix/matrix.js +50 -11
- 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 +139 -35
- package/dist/mjs/data-structures/queue/deque.js +205 -67
- package/dist/mjs/data-structures/queue/queue.d.ts +103 -49
- package/dist/mjs/data-structures/queue/queue.js +111 -49
- package/dist/mjs/data-structures/stack/stack.d.ts +51 -21
- package/dist/mjs/data-structures/stack/stack.js +58 -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 +135 -34
- package/dist/mjs/data-structures/trie/trie.js +156 -36
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/mjs/types/utils/utils.d.ts +1 -0
- package/dist/umd/data-structure-typed.js +3121 -1583
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +61 -55
- package/src/data-structures/base/iterable-base.ts +184 -19
- package/src/data-structures/binary-tree/avl-tree.ts +134 -100
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +127 -136
- package/src/data-structures/binary-tree/rb-tree.ts +199 -166
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
- package/src/data-structures/graph/abstract-graph.ts +4 -211
- package/src/data-structures/graph/directed-graph.ts +152 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +171 -19
- package/src/data-structures/hash/hash-map.ts +389 -96
- package/src/data-structures/heap/heap.ts +97 -26
- package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
- package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- 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 +225 -70
- package/src/data-structures/queue/queue.ts +118 -49
- package/src/data-structures/stack/stack.ts +63 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +173 -38
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
- package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/performance/data-structures/queue/deque.test.ts +26 -25
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
- package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
- package/test/unit/data-structures/graph/abstract-graph.test.ts +11 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +190 -5
- package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
- package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
- package/test/unit/data-structures/heap/heap.test.ts +18 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +65 -5
- package/test/unit/data-structures/queue/queue.test.ts +24 -5
- package/test/unit/data-structures/stack/stack.test.ts +17 -0
- package/test/unit/data-structures/trie/trie.test.ts +17 -0
|
@@ -24,8 +24,16 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
24
24
|
*/
|
|
25
25
|
constructor(elements?: Iterable<E>);
|
|
26
26
|
protected _elements: E[];
|
|
27
|
+
/**
|
|
28
|
+
* The elements function returns the elements of this set.
|
|
29
|
+
* @return An array of the elements in the stack
|
|
30
|
+
*/
|
|
27
31
|
get elements(): E[];
|
|
28
32
|
protected _offset: number;
|
|
33
|
+
/**
|
|
34
|
+
* The offset function returns the offset of the current page.
|
|
35
|
+
* @return The value of the protected variable _offset
|
|
36
|
+
*/
|
|
29
37
|
get offset(): number;
|
|
30
38
|
/**
|
|
31
39
|
* The size function returns the number of elements in an array.
|
|
@@ -33,8 +41,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
33
41
|
*/
|
|
34
42
|
get size(): number;
|
|
35
43
|
/**
|
|
36
|
-
* Time Complexity: O(1)
|
|
37
|
-
* 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)
|
|
38
50
|
*
|
|
39
51
|
* The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
40
52
|
* @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -42,12 +54,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
42
54
|
*/
|
|
43
55
|
get first(): E | undefined;
|
|
44
56
|
/**
|
|
45
|
-
* Time Complexity: O(1)
|
|
46
|
-
* Space Complexity: O(1)
|
|
57
|
+
* Time Complexity: O(1)
|
|
58
|
+
* Space Complexity: O(1)
|
|
47
59
|
*/
|
|
48
60
|
/**
|
|
49
|
-
* Time Complexity: O(1)
|
|
50
|
-
* Space Complexity: O(1)
|
|
61
|
+
* Time Complexity: O(1)
|
|
62
|
+
* Space Complexity: O(1)
|
|
51
63
|
*
|
|
52
64
|
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
53
65
|
* @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -55,10 +67,13 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
55
67
|
*/
|
|
56
68
|
get last(): E | undefined;
|
|
57
69
|
/**
|
|
58
|
-
* Time Complexity: O(n)
|
|
59
|
-
* Space Complexity: O(
|
|
70
|
+
* Time Complexity: O(n)
|
|
71
|
+
* Space Complexity: O(n)
|
|
60
72
|
*/
|
|
61
73
|
/**
|
|
74
|
+
* Time Complexity: O(n)
|
|
75
|
+
* Space Complexity: O(n)
|
|
76
|
+
*
|
|
62
77
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
63
78
|
* @public
|
|
64
79
|
* @static
|
|
@@ -68,12 +83,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
68
83
|
*/
|
|
69
84
|
static fromArray<E>(elements: E[]): Queue<E>;
|
|
70
85
|
/**
|
|
71
|
-
* Time Complexity: O(1)
|
|
72
|
-
* Space Complexity: O(1)
|
|
86
|
+
* Time Complexity: O(1)
|
|
87
|
+
* Space Complexity: O(1)
|
|
73
88
|
*/
|
|
74
89
|
/**
|
|
75
|
-
* Time Complexity: O(1)
|
|
76
|
-
* Space Complexity: O(1)
|
|
90
|
+
* Time Complexity: O(1)
|
|
91
|
+
* Space Complexity: O(1)
|
|
77
92
|
*
|
|
78
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.
|
|
79
94
|
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
@@ -81,12 +96,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
81
96
|
*/
|
|
82
97
|
push(element: E): boolean;
|
|
83
98
|
/**
|
|
84
|
-
* Time Complexity: O(1)
|
|
85
|
-
* Space Complexity: O(1)
|
|
99
|
+
* Time Complexity: O(1)
|
|
100
|
+
* Space Complexity: O(1)
|
|
86
101
|
*/
|
|
87
102
|
/**
|
|
88
|
-
* Time Complexity: O(
|
|
89
|
-
* Space Complexity: O(1)
|
|
103
|
+
* Time Complexity: O(1)
|
|
104
|
+
* Space Complexity: O(1)
|
|
90
105
|
*
|
|
91
106
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
92
107
|
* necessary to optimize performance.
|
|
@@ -94,12 +109,24 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
94
109
|
*/
|
|
95
110
|
shift(): E | undefined;
|
|
96
111
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
112
|
+
* The delete function removes an element from the list.
|
|
113
|
+
* @param element: E Specify the element to be deleted
|
|
114
|
+
* @return A boolean value indicating whether the element was successfully deleted or not
|
|
115
|
+
*/
|
|
116
|
+
delete(element: E): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* The deleteAt function deletes the element at a given index.
|
|
119
|
+
* @param index: number Determine the index of the element to be deleted
|
|
120
|
+
* @return A boolean value
|
|
121
|
+
*/
|
|
122
|
+
deleteAt(index: number): boolean;
|
|
123
|
+
/**
|
|
124
|
+
* Time Complexity: O(1)
|
|
125
|
+
* Space Complexity: O(1)
|
|
99
126
|
*/
|
|
100
127
|
/**
|
|
101
|
-
* Time Complexity: O(1)
|
|
102
|
-
* Space Complexity: O(1)
|
|
128
|
+
* Time Complexity: O(1)
|
|
129
|
+
* Space Complexity: O(1)
|
|
103
130
|
*
|
|
104
131
|
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
105
132
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -107,12 +134,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
107
134
|
*/
|
|
108
135
|
peek(): E | undefined;
|
|
109
136
|
/**
|
|
110
|
-
* Time Complexity: O(1)
|
|
111
|
-
* Space Complexity: O(1)
|
|
137
|
+
* Time Complexity: O(1)
|
|
138
|
+
* Space Complexity: O(1)
|
|
112
139
|
*/
|
|
113
140
|
/**
|
|
114
|
-
* Time Complexity: O(1)
|
|
115
|
-
* Space Complexity: O(1)
|
|
141
|
+
* Time Complexity: O(1)
|
|
142
|
+
* Space Complexity: O(1)
|
|
116
143
|
*
|
|
117
144
|
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
118
145
|
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -120,75 +147,83 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
120
147
|
*/
|
|
121
148
|
peekLast(): E | undefined;
|
|
122
149
|
/**
|
|
123
|
-
* Time Complexity: O(1)
|
|
124
|
-
* Space Complexity: O(1)
|
|
150
|
+
* Time Complexity: O(1)
|
|
151
|
+
* Space Complexity: O(1)
|
|
125
152
|
*/
|
|
126
153
|
/**
|
|
127
|
-
* Time Complexity: O(1)
|
|
128
|
-
* Space Complexity: O(1)
|
|
154
|
+
* Time Complexity: O(1)
|
|
155
|
+
* Space Complexity: O(1)
|
|
129
156
|
*
|
|
130
157
|
* The enqueue function adds a value to the end of a queue.
|
|
131
158
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
132
159
|
*/
|
|
133
160
|
enqueue(value: E): boolean;
|
|
134
161
|
/**
|
|
135
|
-
* Time Complexity: O(
|
|
136
|
-
* Space Complexity: O(1)
|
|
162
|
+
* Time Complexity: O(1)
|
|
163
|
+
* Space Complexity: O(1)
|
|
137
164
|
*/
|
|
138
165
|
/**
|
|
139
|
-
* Time Complexity: O(
|
|
140
|
-
* Space Complexity: O(1)
|
|
166
|
+
* Time Complexity: O(1)
|
|
167
|
+
* Space Complexity: O(1)
|
|
141
168
|
*
|
|
142
169
|
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
143
170
|
* @returns The method is returning a value of type E or undefined.
|
|
144
171
|
*/
|
|
145
172
|
dequeue(): E | undefined;
|
|
146
173
|
/**
|
|
147
|
-
* Time Complexity: O(1)
|
|
148
|
-
* Space Complexity: O(1)
|
|
174
|
+
* Time Complexity: O(1)
|
|
175
|
+
* Space Complexity: O(1)
|
|
149
176
|
*/
|
|
150
177
|
/**
|
|
151
|
-
* Time Complexity: O(1)
|
|
152
|
-
* Space Complexity: O(1)
|
|
178
|
+
* Time Complexity: O(1)
|
|
179
|
+
* Space Complexity: O(1)
|
|
153
180
|
*
|
|
154
181
|
* @param index
|
|
155
182
|
*/
|
|
156
|
-
|
|
183
|
+
at(index: number): E | undefined;
|
|
157
184
|
/**
|
|
158
|
-
* Time Complexity: O(1)
|
|
159
|
-
* Space Complexity: O(1)
|
|
185
|
+
* Time Complexity: O(1)
|
|
186
|
+
* Space Complexity: O(1)
|
|
160
187
|
*/
|
|
161
188
|
/**
|
|
162
|
-
* Time Complexity: O(1)
|
|
163
|
-
* Space Complexity: O(1)
|
|
189
|
+
* Time Complexity: O(1)
|
|
190
|
+
* Space Complexity: O(1)
|
|
164
191
|
*
|
|
165
192
|
* The function checks if a data structure is empty by comparing its size to zero.
|
|
166
193
|
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
167
194
|
*/
|
|
168
195
|
isEmpty(): boolean;
|
|
169
196
|
/**
|
|
170
|
-
* Time Complexity: O(1)
|
|
171
|
-
* Space Complexity: O(n)
|
|
197
|
+
* Time Complexity: O(1)
|
|
198
|
+
* Space Complexity: O(n)
|
|
172
199
|
*/
|
|
173
200
|
/**
|
|
174
|
-
* Time Complexity: O(1)
|
|
175
|
-
* Space Complexity: O(n)
|
|
201
|
+
* Time Complexity: O(1)
|
|
202
|
+
* Space Complexity: O(n)
|
|
176
203
|
*
|
|
177
204
|
* The toArray() function returns an array of elements from the current offset to the end of the _elements array.
|
|
178
205
|
* @returns An array of type E is being returned.
|
|
179
206
|
*/
|
|
180
207
|
toArray(): E[];
|
|
181
208
|
/**
|
|
209
|
+
* Time Complexity: O(1)
|
|
210
|
+
* Space Complexity: O(1)
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* Time Complexity: O(1)
|
|
214
|
+
* Space Complexity: O(1)
|
|
215
|
+
*
|
|
182
216
|
* The clear function resets the elements array and offset to their initial values.
|
|
183
217
|
*/
|
|
184
218
|
clear(): void;
|
|
185
219
|
/**
|
|
186
|
-
* Time Complexity: O(n)
|
|
187
|
-
* Space Complexity: O(n)
|
|
220
|
+
* Time Complexity: O(n)
|
|
221
|
+
* Space Complexity: O(n)
|
|
222
|
+
* where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
|
|
188
223
|
*/
|
|
189
224
|
/**
|
|
190
|
-
* Time Complexity: O(n)
|
|
191
|
-
* Space Complexity: O(n)
|
|
225
|
+
* Time Complexity: O(n)
|
|
226
|
+
* Space Complexity: O(n)
|
|
192
227
|
*
|
|
193
228
|
* The `clone()` function returns a new Queue object with the same elements as the original Queue.
|
|
194
229
|
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
@@ -238,6 +273,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
238
273
|
* Time Complexity: O(n)
|
|
239
274
|
* Space Complexity: O(n)
|
|
240
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
|
+
*/
|
|
241
282
|
protected _getIterator(): IterableIterator<E>;
|
|
242
283
|
}
|
|
243
284
|
/**
|
|
@@ -267,4 +308,17 @@ export declare class LinkedListQueue<E = any> extends SinglyLinkedList<E> {
|
|
|
267
308
|
* @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
|
|
268
309
|
*/
|
|
269
310
|
peek(): E | undefined;
|
|
311
|
+
/**
|
|
312
|
+
* Time Complexity: O(n)
|
|
313
|
+
* Space Complexity: O(n)
|
|
314
|
+
*/
|
|
315
|
+
/**
|
|
316
|
+
* Time Complexity: O(n)
|
|
317
|
+
* Space Complexity: O(n)
|
|
318
|
+
* The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
|
|
319
|
+
* the current instance.
|
|
320
|
+
* @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
|
|
321
|
+
* values as the original `LinkedListQueue`.
|
|
322
|
+
*/
|
|
323
|
+
clone(): LinkedListQueue<E>;
|
|
270
324
|
}
|
|
@@ -24,10 +24,18 @@ export class Queue extends IterableElementBase {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
_elements = [];
|
|
27
|
+
/**
|
|
28
|
+
* The elements function returns the elements of this set.
|
|
29
|
+
* @return An array of the elements in the stack
|
|
30
|
+
*/
|
|
27
31
|
get elements() {
|
|
28
32
|
return this._elements;
|
|
29
33
|
}
|
|
30
34
|
_offset = 0;
|
|
35
|
+
/**
|
|
36
|
+
* The offset function returns the offset of the current page.
|
|
37
|
+
* @return The value of the protected variable _offset
|
|
38
|
+
*/
|
|
31
39
|
get offset() {
|
|
32
40
|
return this._offset;
|
|
33
41
|
}
|
|
@@ -39,8 +47,12 @@ export class Queue extends IterableElementBase {
|
|
|
39
47
|
return this.elements.length - this.offset;
|
|
40
48
|
}
|
|
41
49
|
/**
|
|
42
|
-
* Time Complexity: O(1)
|
|
43
|
-
* Space Complexity: O(1)
|
|
50
|
+
* Time Complexity: O(1)
|
|
51
|
+
* Space Complexity: O(1)
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* Time Complexity: O(1)
|
|
55
|
+
* Space Complexity: O(1)
|
|
44
56
|
*
|
|
45
57
|
* The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
46
58
|
* @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -50,12 +62,12 @@ export class Queue extends IterableElementBase {
|
|
|
50
62
|
return this.size > 0 ? this.elements[this.offset] : undefined;
|
|
51
63
|
}
|
|
52
64
|
/**
|
|
53
|
-
* Time Complexity: O(1)
|
|
54
|
-
* Space Complexity: O(1)
|
|
65
|
+
* Time Complexity: O(1)
|
|
66
|
+
* Space Complexity: O(1)
|
|
55
67
|
*/
|
|
56
68
|
/**
|
|
57
|
-
* Time Complexity: O(1)
|
|
58
|
-
* Space Complexity: O(1)
|
|
69
|
+
* Time Complexity: O(1)
|
|
70
|
+
* Space Complexity: O(1)
|
|
59
71
|
*
|
|
60
72
|
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
61
73
|
* @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -65,10 +77,13 @@ export class Queue extends IterableElementBase {
|
|
|
65
77
|
return this.size > 0 ? this.elements[this.elements.length - 1] : undefined;
|
|
66
78
|
}
|
|
67
79
|
/**
|
|
68
|
-
* Time Complexity: O(n)
|
|
69
|
-
* Space Complexity: O(
|
|
80
|
+
* Time Complexity: O(n)
|
|
81
|
+
* Space Complexity: O(n)
|
|
70
82
|
*/
|
|
71
83
|
/**
|
|
84
|
+
* Time Complexity: O(n)
|
|
85
|
+
* Space Complexity: O(n)
|
|
86
|
+
*
|
|
72
87
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
73
88
|
* @public
|
|
74
89
|
* @static
|
|
@@ -80,12 +95,12 @@ export class Queue extends IterableElementBase {
|
|
|
80
95
|
return new Queue(elements);
|
|
81
96
|
}
|
|
82
97
|
/**
|
|
83
|
-
* Time Complexity: O(1)
|
|
84
|
-
* Space Complexity: O(1)
|
|
98
|
+
* Time Complexity: O(1)
|
|
99
|
+
* Space Complexity: O(1)
|
|
85
100
|
*/
|
|
86
101
|
/**
|
|
87
|
-
* Time Complexity: O(1)
|
|
88
|
-
* Space Complexity: O(1)
|
|
102
|
+
* Time Complexity: O(1)
|
|
103
|
+
* Space Complexity: O(1)
|
|
89
104
|
*
|
|
90
105
|
* 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.
|
|
91
106
|
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
@@ -96,12 +111,12 @@ export class Queue extends IterableElementBase {
|
|
|
96
111
|
return true;
|
|
97
112
|
}
|
|
98
113
|
/**
|
|
99
|
-
* Time Complexity: O(1)
|
|
100
|
-
* Space Complexity: O(1)
|
|
114
|
+
* Time Complexity: O(1)
|
|
115
|
+
* Space Complexity: O(1)
|
|
101
116
|
*/
|
|
102
117
|
/**
|
|
103
|
-
* Time Complexity: O(
|
|
104
|
-
* Space Complexity: O(1)
|
|
118
|
+
* Time Complexity: O(1)
|
|
119
|
+
* Space Complexity: O(1)
|
|
105
120
|
*
|
|
106
121
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
107
122
|
* necessary to optimize performance.
|
|
@@ -121,12 +136,30 @@ export class Queue extends IterableElementBase {
|
|
|
121
136
|
return first;
|
|
122
137
|
}
|
|
123
138
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
139
|
+
* The delete function removes an element from the list.
|
|
140
|
+
* @param element: E Specify the element to be deleted
|
|
141
|
+
* @return A boolean value indicating whether the element was successfully deleted or not
|
|
142
|
+
*/
|
|
143
|
+
delete(element) {
|
|
144
|
+
const index = this.elements.indexOf(element);
|
|
145
|
+
return this.deleteAt(index);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The deleteAt function deletes the element at a given index.
|
|
149
|
+
* @param index: number Determine the index of the element to be deleted
|
|
150
|
+
* @return A boolean value
|
|
151
|
+
*/
|
|
152
|
+
deleteAt(index) {
|
|
153
|
+
const spliced = this.elements.splice(index, 1);
|
|
154
|
+
return spliced.length === 1;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Time Complexity: O(1)
|
|
158
|
+
* Space Complexity: O(1)
|
|
126
159
|
*/
|
|
127
160
|
/**
|
|
128
|
-
* Time Complexity: O(1)
|
|
129
|
-
* Space Complexity: O(1)
|
|
161
|
+
* Time Complexity: O(1)
|
|
162
|
+
* Space Complexity: O(1)
|
|
130
163
|
*
|
|
131
164
|
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
132
165
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -136,12 +169,12 @@ export class Queue extends IterableElementBase {
|
|
|
136
169
|
return this.first;
|
|
137
170
|
}
|
|
138
171
|
/**
|
|
139
|
-
* Time Complexity: O(1)
|
|
140
|
-
* Space Complexity: O(1)
|
|
172
|
+
* Time Complexity: O(1)
|
|
173
|
+
* Space Complexity: O(1)
|
|
141
174
|
*/
|
|
142
175
|
/**
|
|
143
|
-
* Time Complexity: O(1)
|
|
144
|
-
* Space Complexity: O(1)
|
|
176
|
+
* Time Complexity: O(1)
|
|
177
|
+
* Space Complexity: O(1)
|
|
145
178
|
*
|
|
146
179
|
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
147
180
|
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -151,12 +184,12 @@ export class Queue extends IterableElementBase {
|
|
|
151
184
|
return this.last;
|
|
152
185
|
}
|
|
153
186
|
/**
|
|
154
|
-
* Time Complexity: O(1)
|
|
155
|
-
* Space Complexity: O(1)
|
|
187
|
+
* Time Complexity: O(1)
|
|
188
|
+
* Space Complexity: O(1)
|
|
156
189
|
*/
|
|
157
190
|
/**
|
|
158
|
-
* Time Complexity: O(1)
|
|
159
|
-
* Space Complexity: O(1)
|
|
191
|
+
* Time Complexity: O(1)
|
|
192
|
+
* Space Complexity: O(1)
|
|
160
193
|
*
|
|
161
194
|
* The enqueue function adds a value to the end of a queue.
|
|
162
195
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
@@ -165,12 +198,12 @@ export class Queue extends IterableElementBase {
|
|
|
165
198
|
return this.push(value);
|
|
166
199
|
}
|
|
167
200
|
/**
|
|
168
|
-
* Time Complexity: O(
|
|
169
|
-
* Space Complexity: O(1)
|
|
201
|
+
* Time Complexity: O(1)
|
|
202
|
+
* Space Complexity: O(1)
|
|
170
203
|
*/
|
|
171
204
|
/**
|
|
172
|
-
* Time Complexity: O(
|
|
173
|
-
* Space Complexity: O(1)
|
|
205
|
+
* Time Complexity: O(1)
|
|
206
|
+
* Space Complexity: O(1)
|
|
174
207
|
*
|
|
175
208
|
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
176
209
|
* @returns The method is returning a value of type E or undefined.
|
|
@@ -179,25 +212,25 @@ export class Queue extends IterableElementBase {
|
|
|
179
212
|
return this.shift();
|
|
180
213
|
}
|
|
181
214
|
/**
|
|
182
|
-
* Time Complexity: O(1)
|
|
183
|
-
* Space Complexity: O(1)
|
|
215
|
+
* Time Complexity: O(1)
|
|
216
|
+
* Space Complexity: O(1)
|
|
184
217
|
*/
|
|
185
218
|
/**
|
|
186
|
-
* Time Complexity: O(1)
|
|
187
|
-
* Space Complexity: O(1)
|
|
219
|
+
* Time Complexity: O(1)
|
|
220
|
+
* Space Complexity: O(1)
|
|
188
221
|
*
|
|
189
222
|
* @param index
|
|
190
223
|
*/
|
|
191
|
-
|
|
224
|
+
at(index) {
|
|
192
225
|
return this.elements[index];
|
|
193
226
|
}
|
|
194
227
|
/**
|
|
195
|
-
* Time Complexity: O(1)
|
|
196
|
-
* Space Complexity: O(1)
|
|
228
|
+
* Time Complexity: O(1)
|
|
229
|
+
* Space Complexity: O(1)
|
|
197
230
|
*/
|
|
198
231
|
/**
|
|
199
|
-
* Time Complexity: O(1)
|
|
200
|
-
* Space Complexity: O(1)
|
|
232
|
+
* Time Complexity: O(1)
|
|
233
|
+
* Space Complexity: O(1)
|
|
201
234
|
*
|
|
202
235
|
* The function checks if a data structure is empty by comparing its size to zero.
|
|
203
236
|
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
@@ -206,12 +239,12 @@ export class Queue extends IterableElementBase {
|
|
|
206
239
|
return this.size === 0;
|
|
207
240
|
}
|
|
208
241
|
/**
|
|
209
|
-
* Time Complexity: O(1)
|
|
210
|
-
* Space Complexity: O(n)
|
|
242
|
+
* Time Complexity: O(1)
|
|
243
|
+
* Space Complexity: O(n)
|
|
211
244
|
*/
|
|
212
245
|
/**
|
|
213
|
-
* Time Complexity: O(1)
|
|
214
|
-
* Space Complexity: O(n)
|
|
246
|
+
* Time Complexity: O(1)
|
|
247
|
+
* Space Complexity: O(n)
|
|
215
248
|
*
|
|
216
249
|
* The toArray() function returns an array of elements from the current offset to the end of the _elements array.
|
|
217
250
|
* @returns An array of type E is being returned.
|
|
@@ -220,6 +253,13 @@ export class Queue extends IterableElementBase {
|
|
|
220
253
|
return this.elements.slice(this.offset);
|
|
221
254
|
}
|
|
222
255
|
/**
|
|
256
|
+
* Time Complexity: O(1)
|
|
257
|
+
* Space Complexity: O(1)
|
|
258
|
+
*/
|
|
259
|
+
/**
|
|
260
|
+
* Time Complexity: O(1)
|
|
261
|
+
* Space Complexity: O(1)
|
|
262
|
+
*
|
|
223
263
|
* The clear function resets the elements array and offset to their initial values.
|
|
224
264
|
*/
|
|
225
265
|
clear() {
|
|
@@ -227,12 +267,13 @@ export class Queue extends IterableElementBase {
|
|
|
227
267
|
this._offset = 0;
|
|
228
268
|
}
|
|
229
269
|
/**
|
|
230
|
-
* Time Complexity: O(n)
|
|
231
|
-
* Space Complexity: O(n)
|
|
270
|
+
* Time Complexity: O(n)
|
|
271
|
+
* Space Complexity: O(n)
|
|
272
|
+
* where n is the number of elements in the queue. It creates a shallow copy of the internal array. the space required is proportional to the number of elements in the queue.
|
|
232
273
|
*/
|
|
233
274
|
/**
|
|
234
|
-
* Time Complexity: O(n)
|
|
235
|
-
* Space Complexity: O(n)
|
|
275
|
+
* Time Complexity: O(n)
|
|
276
|
+
* Space Complexity: O(n)
|
|
236
277
|
*
|
|
237
278
|
* The `clone()` function returns a new Queue object with the same elements as the original Queue.
|
|
238
279
|
* @returns The `clone()` method is returning a new instance of the `Queue` class.
|
|
@@ -302,6 +343,12 @@ export class Queue extends IterableElementBase {
|
|
|
302
343
|
* Time Complexity: O(n)
|
|
303
344
|
* Space Complexity: O(n)
|
|
304
345
|
*/
|
|
346
|
+
/**
|
|
347
|
+
* Time Complexity: O(n)
|
|
348
|
+
* Space Complexity: O(n)
|
|
349
|
+
*
|
|
350
|
+
* The function `_getIterator` returns an iterable iterator for the elements in the class.
|
|
351
|
+
*/
|
|
305
352
|
*_getIterator() {
|
|
306
353
|
for (const item of this.elements) {
|
|
307
354
|
yield item;
|
|
@@ -343,4 +390,19 @@ export class LinkedListQueue extends SinglyLinkedList {
|
|
|
343
390
|
peek() {
|
|
344
391
|
return this.first;
|
|
345
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Time Complexity: O(n)
|
|
395
|
+
* Space Complexity: O(n)
|
|
396
|
+
*/
|
|
397
|
+
/**
|
|
398
|
+
* Time Complexity: O(n)
|
|
399
|
+
* Space Complexity: O(n)
|
|
400
|
+
* The `clone` function returns a new instance of the `LinkedListQueue` class with the same values as
|
|
401
|
+
* the current instance.
|
|
402
|
+
* @returns The `clone()` method is returning a new instance of `LinkedListQueue` with the same
|
|
403
|
+
* values as the original `LinkedListQueue`.
|
|
404
|
+
*/
|
|
405
|
+
clone() {
|
|
406
|
+
return new LinkedListQueue(this.values());
|
|
407
|
+
}
|
|
346
408
|
}
|