data-structure-typed 1.48.5 → 1.48.7
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 +109 -59
- package/README_zh-CN.md +1028 -0
- package/benchmark/report.html +16 -16
- package/benchmark/report.json +204 -174
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +7 -16
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +24 -19
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +35 -11
- package/dist/cjs/data-structures/binary-tree/bst.js +58 -39
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +4 -4
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +4 -4
- 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 +4 -4
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +4 -4
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +9 -9
- package/dist/cjs/data-structures/queue/deque.js +9 -9
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +7 -16
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +24 -19
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +35 -11
- package/dist/mjs/data-structures/binary-tree/bst.js +58 -39
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +4 -4
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +4 -4
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +4 -4
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +4 -4
- package/dist/mjs/data-structures/queue/deque.d.ts +9 -9
- package/dist/mjs/data-structures/queue/deque.js +9 -9
- package/dist/mjs/interfaces/binary-tree.d.ts +1 -1
- package/dist/umd/data-structure-typed.js +99 -78
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +31 -20
- package/src/data-structures/binary-tree/bst.ts +73 -46
- package/src/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/data-structures/binary-tree/tree-multimap.ts +1 -1
- package/src/data-structures/hash/hash-map.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
- package/src/data-structures/linked-list/singly-linked-list.ts +4 -4
- package/src/data-structures/queue/deque.ts +10 -10
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/data-structures/heap/heap.ts +1 -1
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +1 -1
- package/test/performance/data-structures/hash/hash-map.test.ts +8 -8
- 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 +12 -1
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +1 -1
- package/test/performance/data-structures/queue/deque.test.ts +27 -15
- package/test/performance/data-structures/queue/queue.test.ts +27 -4
- package/test/performance/data-structures/stack/stack.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/bst.test.ts +29 -29
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +2 -2
- package/test/unit/data-structures/queue/deque.test.ts +15 -15
|
@@ -113,19 +113,43 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
113
113
|
* Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
|
|
114
114
|
* Space Complexity: O(k) - Additional space is required for the sorted array.
|
|
115
115
|
*
|
|
116
|
-
* The `addMany` function in TypeScript adds multiple nodes to a binary tree,
|
|
117
|
-
*
|
|
118
|
-
* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to
|
|
119
|
-
* binary tree.
|
|
120
|
-
* @param [
|
|
121
|
-
*
|
|
116
|
+
* The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
|
|
117
|
+
* balancing the tree after each addition.
|
|
118
|
+
* @param keysOrNodesOrEntries - An iterable containing the keys, nodes, or entries to be added to
|
|
119
|
+
* the binary tree.
|
|
120
|
+
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
121
|
+
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
122
|
+
* order. If not provided, undefined will be assigned as the value for each key or node.
|
|
123
|
+
* @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
|
|
124
|
+
* balanced or not. If set to true, the add operation will be balanced using a binary search tree
|
|
125
|
+
* algorithm. If set to false, the add operation will not be balanced and the elements will be added
|
|
126
|
+
* in the order they appear in the input.
|
|
122
127
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
123
|
-
* type of iteration to use when adding multiple keys or nodes
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* @returns The `addMany` function returns an array of `N` or `undefined` values.
|
|
128
|
+
* type of iteration to use when adding multiple keys or nodes. It has a default value of
|
|
129
|
+
* `this.iterationType`, which suggests that it is a property of the current object.
|
|
130
|
+
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
|
|
127
131
|
*/
|
|
128
|
-
addMany(keysOrNodesOrEntries: Iterable<BTNodeExemplar<K, V, N>>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
|
|
132
|
+
addMany(keysOrNodesOrEntries: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>, isBalanceAdd?: boolean, iterationType?: IterationType): (N | undefined)[];
|
|
133
|
+
/**
|
|
134
|
+
* Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
|
|
135
|
+
* Space Complexity: O(n) - Additional space is required for the sorted array.
|
|
136
|
+
*/
|
|
137
|
+
/**
|
|
138
|
+
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
139
|
+
* Space Complexity: O(1) - Constant space is used.
|
|
140
|
+
*
|
|
141
|
+
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
|
|
142
|
+
* leftmost node if the comparison result is greater than.
|
|
143
|
+
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
|
|
144
|
+
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
|
|
145
|
+
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
|
|
146
|
+
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
147
|
+
* be performed. It can have one of the following values:
|
|
148
|
+
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
|
|
149
|
+
* the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
150
|
+
* rightmost node otherwise. If no node is found, it returns 0.
|
|
151
|
+
*/
|
|
152
|
+
lastKey(beginRoot?: BSTNodeKeyOrNode<K, N>): K | undefined;
|
|
129
153
|
/**
|
|
130
154
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
131
155
|
* Space Complexity: O(1) - Constant space is used.
|
|
@@ -214,23 +214,32 @@ export class BST extends BinaryTree {
|
|
|
214
214
|
* Time Complexity: O(k log n) - Adding each element individually in a balanced tree.
|
|
215
215
|
* Space Complexity: O(k) - Additional space is required for the sorted array.
|
|
216
216
|
*
|
|
217
|
-
* The `addMany` function in TypeScript adds multiple nodes to a binary tree,
|
|
218
|
-
*
|
|
219
|
-
* @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to
|
|
220
|
-
* binary tree.
|
|
221
|
-
* @param [
|
|
222
|
-
*
|
|
217
|
+
* The `addMany` function in TypeScript adds multiple keys or nodes to a binary tree, optionally
|
|
218
|
+
* balancing the tree after each addition.
|
|
219
|
+
* @param keysOrNodesOrEntries - An iterable containing the keys, nodes, or entries to be added to
|
|
220
|
+
* the binary tree.
|
|
221
|
+
* @param [values] - An optional iterable of values to be associated with the keys or nodes being
|
|
222
|
+
* added. If provided, the values will be assigned to the corresponding keys or nodes in the same
|
|
223
|
+
* order. If not provided, undefined will be assigned as the value for each key or node.
|
|
224
|
+
* @param [isBalanceAdd=true] - A boolean flag indicating whether the add operation should be
|
|
225
|
+
* balanced or not. If set to true, the add operation will be balanced using a binary search tree
|
|
226
|
+
* algorithm. If set to false, the add operation will not be balanced and the elements will be added
|
|
227
|
+
* in the order they appear in the input.
|
|
223
228
|
* @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
|
|
224
|
-
* type of iteration to use when adding multiple keys or nodes
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* @returns The `addMany` function returns an array of `N` or `undefined` values.
|
|
229
|
+
* type of iteration to use when adding multiple keys or nodes. It has a default value of
|
|
230
|
+
* `this.iterationType`, which suggests that it is a property of the current object.
|
|
231
|
+
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
|
|
228
232
|
*/
|
|
229
|
-
addMany(keysOrNodesOrEntries, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
233
|
+
addMany(keysOrNodesOrEntries, values, isBalanceAdd = true, iterationType = this.iterationType) {
|
|
230
234
|
const inserted = [];
|
|
235
|
+
let valuesIterator;
|
|
236
|
+
if (values) {
|
|
237
|
+
valuesIterator = values[Symbol.iterator]();
|
|
238
|
+
}
|
|
231
239
|
if (!isBalanceAdd) {
|
|
232
240
|
for (const kve of keysOrNodesOrEntries) {
|
|
233
|
-
const
|
|
241
|
+
const value = valuesIterator?.next().value;
|
|
242
|
+
const nn = this.add(kve, value);
|
|
234
243
|
inserted.push(nn);
|
|
235
244
|
}
|
|
236
245
|
return inserted;
|
|
@@ -244,7 +253,6 @@ export class BST extends BinaryTree {
|
|
|
244
253
|
for (const kve of keysOrNodesOrEntries) {
|
|
245
254
|
isRealBTNExemplar(kve) && realBTNExemplars.push(kve);
|
|
246
255
|
}
|
|
247
|
-
// TODO this addMany function is inefficient, it should be optimized
|
|
248
256
|
let sorted = [];
|
|
249
257
|
sorted = realBTNExemplars.sort((a, b) => {
|
|
250
258
|
let aR, bR;
|
|
@@ -296,31 +304,43 @@ export class BST extends BinaryTree {
|
|
|
296
304
|
}
|
|
297
305
|
return inserted;
|
|
298
306
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
307
|
+
/**
|
|
308
|
+
* Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
|
|
309
|
+
* Space Complexity: O(n) - Additional space is required for the sorted array.
|
|
310
|
+
*/
|
|
311
|
+
/**
|
|
312
|
+
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
313
|
+
* Space Complexity: O(1) - Constant space is used.
|
|
314
|
+
*
|
|
315
|
+
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
|
|
316
|
+
* leftmost node if the comparison result is greater than.
|
|
317
|
+
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
|
|
318
|
+
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
|
|
319
|
+
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
|
|
320
|
+
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
321
|
+
* be performed. It can have one of the following values:
|
|
322
|
+
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
|
|
323
|
+
* the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
324
|
+
* rightmost node otherwise. If no node is found, it returns 0.
|
|
325
|
+
*/
|
|
326
|
+
lastKey(beginRoot = this.root) {
|
|
327
|
+
let current = this.ensureNode(beginRoot);
|
|
328
|
+
if (!current)
|
|
329
|
+
return undefined;
|
|
330
|
+
if (this._variant === BSTVariant.MIN) {
|
|
331
|
+
// For BSTVariant.MIN, find the rightmost node
|
|
332
|
+
while (current.right !== undefined) {
|
|
333
|
+
current = current.right;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
// For BSTVariant.MAX, find the leftmost node
|
|
338
|
+
while (current.left !== undefined) {
|
|
339
|
+
current = current.left;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return current.key;
|
|
343
|
+
}
|
|
324
344
|
/**
|
|
325
345
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
326
346
|
* Space Complexity: O(1) - Constant space is used.
|
|
@@ -572,7 +592,6 @@ export class BST extends BinaryTree {
|
|
|
572
592
|
if (l <= r) {
|
|
573
593
|
const m = l + Math.floor((r - l) / 2);
|
|
574
594
|
const midNode = sorted[m];
|
|
575
|
-
debugger;
|
|
576
595
|
this.add([midNode.key, midNode.value]);
|
|
577
596
|
stack.push([m + 1, r]);
|
|
578
597
|
stack.push([l, m - 1]);
|
|
@@ -89,11 +89,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
89
89
|
* Time Complexity: O(1)
|
|
90
90
|
* Space Complexity: O(1)
|
|
91
91
|
*
|
|
92
|
-
* The `
|
|
92
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
93
93
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
94
94
|
* list is empty, it returns undefined.
|
|
95
95
|
*/
|
|
96
|
-
|
|
96
|
+
pollLast(): E | undefined;
|
|
97
97
|
/**
|
|
98
98
|
* Time Complexity: O(1)
|
|
99
99
|
* Space Complexity: O(1)
|
|
@@ -115,11 +115,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
115
115
|
* Time Complexity: O(1)
|
|
116
116
|
* Space Complexity: O(1)
|
|
117
117
|
*
|
|
118
|
-
* The `
|
|
118
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
119
119
|
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
120
120
|
* list.
|
|
121
121
|
*/
|
|
122
|
-
|
|
122
|
+
pollFirst(): E | undefined;
|
|
123
123
|
/**
|
|
124
124
|
* Time Complexity: O(1)
|
|
125
125
|
* Space Complexity: O(1)
|
|
@@ -144,11 +144,11 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
144
144
|
* Time Complexity: O(1)
|
|
145
145
|
* Space Complexity: O(1)
|
|
146
146
|
*
|
|
147
|
-
* The `
|
|
147
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
148
148
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
149
149
|
* list is empty, it returns undefined.
|
|
150
150
|
*/
|
|
151
|
-
|
|
151
|
+
pollLast() {
|
|
152
152
|
return this.pop();
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
@@ -186,11 +186,11 @@ export class DoublyLinkedList extends IterableElementBase {
|
|
|
186
186
|
* Time Complexity: O(1)
|
|
187
187
|
* Space Complexity: O(1)
|
|
188
188
|
*
|
|
189
|
-
* The `
|
|
189
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
190
190
|
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
191
191
|
* list.
|
|
192
192
|
*/
|
|
193
|
-
|
|
193
|
+
pollFirst() {
|
|
194
194
|
return this.shift();
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
@@ -90,12 +90,12 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
90
90
|
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
91
91
|
* Space Complexity: O(1) - Constant space.
|
|
92
92
|
*
|
|
93
|
-
* The `
|
|
93
|
+
* The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
94
94
|
* pointers accordingly.
|
|
95
95
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
96
96
|
* the linked list is empty, it returns `undefined`.
|
|
97
97
|
*/
|
|
98
|
-
|
|
98
|
+
pollLast(): E | undefined;
|
|
99
99
|
/**
|
|
100
100
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
101
101
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -116,10 +116,10 @@ export declare class SinglyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
116
116
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
117
117
|
* Space Complexity: O(1) - Constant space.
|
|
118
118
|
*
|
|
119
|
-
* The `
|
|
119
|
+
* The `pollFirst()` function removes and returns the value of the first node in a linked list.
|
|
120
120
|
* @returns The value of the node that is being removed from the beginning of the linked list.
|
|
121
121
|
*/
|
|
122
|
-
|
|
122
|
+
pollFirst(): E | undefined;
|
|
123
123
|
/**
|
|
124
124
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
125
125
|
* Space Complexity: O(1) - Constant space.
|
|
@@ -145,12 +145,12 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
145
145
|
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
146
146
|
* Space Complexity: O(1) - Constant space.
|
|
147
147
|
*
|
|
148
|
-
* The `
|
|
148
|
+
* The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
149
149
|
* pointers accordingly.
|
|
150
150
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
151
151
|
* the linked list is empty, it returns `undefined`.
|
|
152
152
|
*/
|
|
153
|
-
|
|
153
|
+
pollLast() {
|
|
154
154
|
return this.pop();
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
@@ -180,10 +180,10 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
180
180
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
181
181
|
* Space Complexity: O(1) - Constant space.
|
|
182
182
|
*
|
|
183
|
-
* The `
|
|
183
|
+
* The `pollFirst()` function removes and returns the value of the first node in a linked list.
|
|
184
184
|
* @returns The value of the node that is being removed from the beginning of the linked list.
|
|
185
185
|
*/
|
|
186
|
-
|
|
186
|
+
pollFirst() {
|
|
187
187
|
return this.shift();
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
@@ -67,10 +67,10 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
67
67
|
* Time Complexity: O(1) - Removes the last element.
|
|
68
68
|
* Space Complexity: O(1) - Operates in-place.
|
|
69
69
|
*
|
|
70
|
-
* The function "
|
|
70
|
+
* The function "pollLast" removes and returns the last element of an array.
|
|
71
71
|
* @returns The last element of the array is being returned.
|
|
72
72
|
*/
|
|
73
|
-
|
|
73
|
+
pollLast(): E | undefined;
|
|
74
74
|
/**
|
|
75
75
|
* Time Complexity: O(1).
|
|
76
76
|
* Space Complexity: O(n) - Due to potential resizing.
|
|
@@ -84,11 +84,11 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
84
84
|
* Time Complexity: O(1) - Removes the first element.
|
|
85
85
|
* Space Complexity: O(1) - In-place operation.
|
|
86
86
|
*
|
|
87
|
-
* The function "
|
|
88
|
-
* @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
|
|
89
89
|
* from the beginning. If the array is empty, it will return `undefined`.
|
|
90
90
|
*/
|
|
91
|
-
|
|
91
|
+
pollFirst(): E | undefined;
|
|
92
92
|
/**
|
|
93
93
|
* The clear() function resets the state of the object by initializing all variables to their default
|
|
94
94
|
* values.
|
|
@@ -488,10 +488,10 @@ export declare class ObjectDeque<E = number> {
|
|
|
488
488
|
* Time Complexity: O(1)
|
|
489
489
|
* Space Complexity: O(1)
|
|
490
490
|
*
|
|
491
|
-
* The function `
|
|
491
|
+
* The function `pollFirst()` removes and returns the first element in a data structure.
|
|
492
492
|
* @returns The element of the first element in the data structure.
|
|
493
493
|
*/
|
|
494
|
-
|
|
494
|
+
pollFirst(): E | undefined;
|
|
495
495
|
/**
|
|
496
496
|
* Time Complexity: O(1)
|
|
497
497
|
* Space Complexity: O(1)
|
|
@@ -512,10 +512,10 @@ export declare class ObjectDeque<E = number> {
|
|
|
512
512
|
* Time Complexity: O(1)
|
|
513
513
|
* Space Complexity: O(1)
|
|
514
514
|
*
|
|
515
|
-
* The `
|
|
515
|
+
* The `pollLast()` function removes and returns the last element in a data structure.
|
|
516
516
|
* @returns The element that was removed from the data structure.
|
|
517
517
|
*/
|
|
518
|
-
|
|
518
|
+
pollLast(): E | undefined;
|
|
519
519
|
/**
|
|
520
520
|
* Time Complexity: O(1)
|
|
521
521
|
* Space Complexity: O(1)
|
|
@@ -109,10 +109,10 @@ export class Deque extends IterableElementBase {
|
|
|
109
109
|
* Time Complexity: O(1) - Removes the last element.
|
|
110
110
|
* Space Complexity: O(1) - Operates in-place.
|
|
111
111
|
*
|
|
112
|
-
* The function "
|
|
112
|
+
* The function "pollLast" removes and returns the last element of an array.
|
|
113
113
|
* @returns The last element of the array is being returned.
|
|
114
114
|
*/
|
|
115
|
-
|
|
115
|
+
pollLast() {
|
|
116
116
|
return this.pop();
|
|
117
117
|
}
|
|
118
118
|
/**
|
|
@@ -130,11 +130,11 @@ export class Deque extends IterableElementBase {
|
|
|
130
130
|
* Time Complexity: O(1) - Removes the first element.
|
|
131
131
|
* Space Complexity: O(1) - In-place operation.
|
|
132
132
|
*
|
|
133
|
-
* The function "
|
|
134
|
-
* @returns The method `
|
|
133
|
+
* The function "pollFirst" removes and returns the first element of an array.
|
|
134
|
+
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
135
135
|
* from the beginning. If the array is empty, it will return `undefined`.
|
|
136
136
|
*/
|
|
137
|
-
|
|
137
|
+
pollFirst() {
|
|
138
138
|
return this.shift();
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
@@ -872,10 +872,10 @@ export class ObjectDeque {
|
|
|
872
872
|
* Time Complexity: O(1)
|
|
873
873
|
* Space Complexity: O(1)
|
|
874
874
|
*
|
|
875
|
-
* The function `
|
|
875
|
+
* The function `pollFirst()` removes and returns the first element in a data structure.
|
|
876
876
|
* @returns The element of the first element in the data structure.
|
|
877
877
|
*/
|
|
878
|
-
|
|
878
|
+
pollFirst() {
|
|
879
879
|
if (!this.size)
|
|
880
880
|
return;
|
|
881
881
|
const element = this.getFirst();
|
|
@@ -907,10 +907,10 @@ export class ObjectDeque {
|
|
|
907
907
|
* Time Complexity: O(1)
|
|
908
908
|
* Space Complexity: O(1)
|
|
909
909
|
*
|
|
910
|
-
* The `
|
|
910
|
+
* The `pollLast()` function removes and returns the last element in a data structure.
|
|
911
911
|
* @returns The element that was removed from the data structure.
|
|
912
912
|
*/
|
|
913
|
-
|
|
913
|
+
pollLast() {
|
|
914
914
|
if (!this.size)
|
|
915
915
|
return;
|
|
916
916
|
const element = this.getLast();
|
|
@@ -4,6 +4,6 @@ export interface IBinaryTree<K = number, V = any, N extends BinaryTreeNode<K, V,
|
|
|
4
4
|
createNode(key: K, value?: N['value']): N;
|
|
5
5
|
createTree(options?: Partial<BinaryTreeOptions<K>>): TREE;
|
|
6
6
|
add(keyOrNodeOrEntry: BTNodeExemplar<K, V, N>, value?: V, count?: number): N | null | undefined;
|
|
7
|
-
addMany(nodes: Iterable<BTNodeExemplar<K, V, N
|
|
7
|
+
addMany(nodes: Iterable<BTNodeExemplar<K, V, N>>, values?: Iterable<V | undefined>): (N | null | undefined)[];
|
|
8
8
|
delete<C extends BTNCallback<N>>(identifier: ReturnType<C> | null, callback: C): BiTreeDeleteResult<N>[];
|
|
9
9
|
}
|