data-structure-typed 1.48.6 → 1.48.8
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 +42 -51
- package/README_zh-CN.md +35 -44
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -9
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +5 -10
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +20 -0
- package/dist/cjs/data-structures/binary-tree/bst.js +37 -26
- 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/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -9
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +5 -10
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +20 -0
- package/dist/mjs/data-structures/binary-tree/bst.js +37 -26
- 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/umd/data-structure-typed.js +55 -53
- 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/binary-tree.ts +5 -10
- package/src/data-structures/binary-tree/bst.ts +38 -26
- 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/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/unit/data-structures/linked-list/singly-linked-list.test.ts +2 -2
- package/test/unit/data-structures/queue/deque.test.ts +15 -15
|
@@ -130,6 +130,26 @@ export declare class BST<K = any, V = any, N extends BSTNode<K, V, N> = BSTNode<
|
|
|
130
130
|
* @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
|
|
131
131
|
*/
|
|
132
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;
|
|
133
153
|
/**
|
|
134
154
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
135
155
|
* Space Complexity: O(1) - Constant space is used.
|
|
@@ -304,31 +304,43 @@ export class BST extends BinaryTree {
|
|
|
304
304
|
}
|
|
305
305
|
return inserted;
|
|
306
306
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
+
}
|
|
332
344
|
/**
|
|
333
345
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
334
346
|
* Space Complexity: O(1) - Constant space is used.
|
|
@@ -580,7 +592,6 @@ export class BST extends BinaryTree {
|
|
|
580
592
|
if (l <= r) {
|
|
581
593
|
const m = l + Math.floor((r - l) / 2);
|
|
582
594
|
const midNode = sorted[m];
|
|
583
|
-
debugger;
|
|
584
595
|
this.add([midNode.key, midNode.value]);
|
|
585
596
|
stack.push([m + 1, r]);
|
|
586
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();
|
|
@@ -1539,12 +1539,12 @@ var dataStructureTyped = (() => {
|
|
|
1539
1539
|
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
1540
1540
|
* Space Complexity: O(1) - Constant space.
|
|
1541
1541
|
*
|
|
1542
|
-
* The `
|
|
1542
|
+
* The `pollLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
|
|
1543
1543
|
* pointers accordingly.
|
|
1544
1544
|
* @returns The method `pop()` returns the value of the node that is being removed from the end of the linked list. If
|
|
1545
1545
|
* the linked list is empty, it returns `undefined`.
|
|
1546
1546
|
*/
|
|
1547
|
-
|
|
1547
|
+
pollLast() {
|
|
1548
1548
|
return this.pop();
|
|
1549
1549
|
}
|
|
1550
1550
|
/**
|
|
@@ -1574,10 +1574,10 @@ var dataStructureTyped = (() => {
|
|
|
1574
1574
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
1575
1575
|
* Space Complexity: O(1) - Constant space.
|
|
1576
1576
|
*
|
|
1577
|
-
* The `
|
|
1577
|
+
* The `pollFirst()` function removes and returns the value of the first node in a linked list.
|
|
1578
1578
|
* @returns The value of the node that is being removed from the beginning of the linked list.
|
|
1579
1579
|
*/
|
|
1580
|
-
|
|
1580
|
+
pollFirst() {
|
|
1581
1581
|
return this.shift();
|
|
1582
1582
|
}
|
|
1583
1583
|
/**
|
|
@@ -2212,11 +2212,11 @@ var dataStructureTyped = (() => {
|
|
|
2212
2212
|
* Time Complexity: O(1)
|
|
2213
2213
|
* Space Complexity: O(1)
|
|
2214
2214
|
*
|
|
2215
|
-
* The `
|
|
2215
|
+
* The `pollLast()` function removes and returns the value of the last node in a doubly linked list.
|
|
2216
2216
|
* @returns The method is returning the value of the removed node (removedNode.value) if the list is not empty. If the
|
|
2217
2217
|
* list is empty, it returns undefined.
|
|
2218
2218
|
*/
|
|
2219
|
-
|
|
2219
|
+
pollLast() {
|
|
2220
2220
|
return this.pop();
|
|
2221
2221
|
}
|
|
2222
2222
|
/**
|
|
@@ -2253,11 +2253,11 @@ var dataStructureTyped = (() => {
|
|
|
2253
2253
|
* Time Complexity: O(1)
|
|
2254
2254
|
* Space Complexity: O(1)
|
|
2255
2255
|
*
|
|
2256
|
-
* The `
|
|
2256
|
+
* The `pollFirst()` function removes and returns the value of the first node in a doubly linked list.
|
|
2257
2257
|
* @returns The method `shift()` returns the value of the node that is removed from the beginning of the doubly linked
|
|
2258
2258
|
* list.
|
|
2259
2259
|
*/
|
|
2260
|
-
|
|
2260
|
+
pollFirst() {
|
|
2261
2261
|
return this.shift();
|
|
2262
2262
|
}
|
|
2263
2263
|
/**
|
|
@@ -3692,10 +3692,10 @@ var dataStructureTyped = (() => {
|
|
|
3692
3692
|
* Time Complexity: O(1) - Removes the last element.
|
|
3693
3693
|
* Space Complexity: O(1) - Operates in-place.
|
|
3694
3694
|
*
|
|
3695
|
-
* The function "
|
|
3695
|
+
* The function "pollLast" removes and returns the last element of an array.
|
|
3696
3696
|
* @returns The last element of the array is being returned.
|
|
3697
3697
|
*/
|
|
3698
|
-
|
|
3698
|
+
pollLast() {
|
|
3699
3699
|
return this.pop();
|
|
3700
3700
|
}
|
|
3701
3701
|
/**
|
|
@@ -3713,11 +3713,11 @@ var dataStructureTyped = (() => {
|
|
|
3713
3713
|
* Time Complexity: O(1) - Removes the first element.
|
|
3714
3714
|
* Space Complexity: O(1) - In-place operation.
|
|
3715
3715
|
*
|
|
3716
|
-
* The function "
|
|
3717
|
-
* @returns The method `
|
|
3716
|
+
* The function "pollFirst" removes and returns the first element of an array.
|
|
3717
|
+
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
3718
3718
|
* from the beginning. If the array is empty, it will return `undefined`.
|
|
3719
3719
|
*/
|
|
3720
|
-
|
|
3720
|
+
pollFirst() {
|
|
3721
3721
|
return this.shift();
|
|
3722
3722
|
}
|
|
3723
3723
|
/**
|
|
@@ -4452,10 +4452,10 @@ var dataStructureTyped = (() => {
|
|
|
4452
4452
|
* Time Complexity: O(1)
|
|
4453
4453
|
* Space Complexity: O(1)
|
|
4454
4454
|
*
|
|
4455
|
-
* The function `
|
|
4455
|
+
* The function `pollFirst()` removes and returns the first element in a data structure.
|
|
4456
4456
|
* @returns The element of the first element in the data structure.
|
|
4457
4457
|
*/
|
|
4458
|
-
|
|
4458
|
+
pollFirst() {
|
|
4459
4459
|
if (!this.size)
|
|
4460
4460
|
return;
|
|
4461
4461
|
const element = this.getFirst();
|
|
@@ -4487,10 +4487,10 @@ var dataStructureTyped = (() => {
|
|
|
4487
4487
|
* Time Complexity: O(1)
|
|
4488
4488
|
* Space Complexity: O(1)
|
|
4489
4489
|
*
|
|
4490
|
-
* The `
|
|
4490
|
+
* The `pollLast()` function removes and returns the last element in a data structure.
|
|
4491
4491
|
* @returns The element that was removed from the data structure.
|
|
4492
4492
|
*/
|
|
4493
|
-
|
|
4493
|
+
pollLast() {
|
|
4494
4494
|
if (!this.size)
|
|
4495
4495
|
return;
|
|
4496
4496
|
const element = this.getLast();
|
|
@@ -7660,6 +7660,8 @@ var dataStructureTyped = (() => {
|
|
|
7660
7660
|
const newNode = this.exemplarToNode(keyOrNodeOrEntry, value);
|
|
7661
7661
|
if (newNode === void 0)
|
|
7662
7662
|
return;
|
|
7663
|
+
if (newNode !== null && this.has(newNode.key))
|
|
7664
|
+
return void 0;
|
|
7663
7665
|
const _bfs = (root, newNode2) => {
|
|
7664
7666
|
const queue = new Queue([root]);
|
|
7665
7667
|
while (queue.size > 0) {
|
|
@@ -7727,17 +7729,9 @@ var dataStructureTyped = (() => {
|
|
|
7727
7729
|
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
7728
7730
|
* Space Complexity: O(1)
|
|
7729
7731
|
*/
|
|
7730
|
-
|
|
7731
|
-
* Time Complexity: O(k * n) "n" is the number of nodes in the tree, and "k" is the number of keys to be inserted.
|
|
7732
|
-
* Space Complexity: O(1)
|
|
7733
|
-
*
|
|
7734
|
-
* The `refill` function clears the current collection and adds new nodes, keys, or entries to it.
|
|
7735
|
-
* @param nodesOrKeysOrEntries - The parameter `nodesOrKeysOrEntries` is an iterable object that can
|
|
7736
|
-
* contain either `BTNodeExemplar` objects, keys, or entries.
|
|
7737
|
-
*/
|
|
7738
|
-
refill(nodesOrKeysOrEntries) {
|
|
7732
|
+
refill(nodesOrKeysOrEntries, values) {
|
|
7739
7733
|
this.clear();
|
|
7740
|
-
this.addMany(nodesOrKeysOrEntries);
|
|
7734
|
+
this.addMany(nodesOrKeysOrEntries, values);
|
|
7741
7735
|
}
|
|
7742
7736
|
/**
|
|
7743
7737
|
* Time Complexity: O(n)
|
|
@@ -9386,31 +9380,40 @@ var dataStructureTyped = (() => {
|
|
|
9386
9380
|
}
|
|
9387
9381
|
return inserted;
|
|
9388
9382
|
}
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
9397
|
-
|
|
9398
|
-
|
|
9399
|
-
|
|
9400
|
-
|
|
9401
|
-
|
|
9402
|
-
|
|
9403
|
-
|
|
9404
|
-
|
|
9405
|
-
|
|
9406
|
-
|
|
9407
|
-
|
|
9408
|
-
|
|
9409
|
-
|
|
9410
|
-
|
|
9411
|
-
|
|
9412
|
-
|
|
9413
|
-
|
|
9383
|
+
/**
|
|
9384
|
+
* Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
|
|
9385
|
+
* Space Complexity: O(n) - Additional space is required for the sorted array.
|
|
9386
|
+
*/
|
|
9387
|
+
/**
|
|
9388
|
+
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
9389
|
+
* Space Complexity: O(1) - Constant space is used.
|
|
9390
|
+
*
|
|
9391
|
+
* The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
|
|
9392
|
+
* leftmost node if the comparison result is greater than.
|
|
9393
|
+
* @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
|
|
9394
|
+
* type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
|
|
9395
|
+
* the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
|
|
9396
|
+
* @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
|
|
9397
|
+
* be performed. It can have one of the following values:
|
|
9398
|
+
* @returns the key of the rightmost node in the binary tree if the comparison result is less than,
|
|
9399
|
+
* the key of the leftmost node if the comparison result is greater than, and the key of the
|
|
9400
|
+
* rightmost node otherwise. If no node is found, it returns 0.
|
|
9401
|
+
*/
|
|
9402
|
+
lastKey(beginRoot = this.root) {
|
|
9403
|
+
let current = this.ensureNode(beginRoot);
|
|
9404
|
+
if (!current)
|
|
9405
|
+
return void 0;
|
|
9406
|
+
if (this._variant === "MIN" /* MIN */) {
|
|
9407
|
+
while (current.right !== void 0) {
|
|
9408
|
+
current = current.right;
|
|
9409
|
+
}
|
|
9410
|
+
} else {
|
|
9411
|
+
while (current.left !== void 0) {
|
|
9412
|
+
current = current.left;
|
|
9413
|
+
}
|
|
9414
|
+
}
|
|
9415
|
+
return current.key;
|
|
9416
|
+
}
|
|
9414
9417
|
/**
|
|
9415
9418
|
* Time Complexity: O(log n) - Average case for a balanced tree.
|
|
9416
9419
|
* Space Complexity: O(1) - Constant space is used.
|
|
@@ -9654,7 +9657,6 @@ var dataStructureTyped = (() => {
|
|
|
9654
9657
|
if (l <= r) {
|
|
9655
9658
|
const m = l + Math.floor((r - l) / 2);
|
|
9656
9659
|
const midNode = sorted[m];
|
|
9657
|
-
debugger;
|
|
9658
9660
|
this.add([midNode.key, midNode.value]);
|
|
9659
9661
|
stack.push([m + 1, r]);
|
|
9660
9662
|
stack.push([l, m - 1]);
|