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.
Files changed (45) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +42 -51
  3. package/README_zh-CN.md +35 -44
  4. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -9
  5. package/dist/cjs/data-structures/binary-tree/binary-tree.js +5 -10
  6. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/bst.d.ts +20 -0
  8. package/dist/cjs/data-structures/binary-tree/bst.js +37 -26
  9. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  10. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  11. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +4 -4
  12. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +4 -4
  13. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  14. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +4 -4
  15. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +4 -4
  16. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  17. package/dist/cjs/data-structures/queue/deque.d.ts +9 -9
  18. package/dist/cjs/data-structures/queue/deque.js +9 -9
  19. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  20. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -9
  21. package/dist/mjs/data-structures/binary-tree/binary-tree.js +5 -10
  22. package/dist/mjs/data-structures/binary-tree/bst.d.ts +20 -0
  23. package/dist/mjs/data-structures/binary-tree/bst.js +37 -26
  24. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +4 -4
  25. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +4 -4
  26. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +4 -4
  27. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +4 -4
  28. package/dist/mjs/data-structures/queue/deque.d.ts +9 -9
  29. package/dist/mjs/data-structures/queue/deque.js +9 -9
  30. package/dist/umd/data-structure-typed.js +55 -53
  31. package/dist/umd/data-structure-typed.min.js +2 -2
  32. package/dist/umd/data-structure-typed.min.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/data-structures/binary-tree/binary-tree.ts +5 -10
  35. package/src/data-structures/binary-tree/bst.ts +38 -26
  36. package/src/data-structures/hash/hash-map.ts +1 -1
  37. package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
  38. package/src/data-structures/linked-list/singly-linked-list.ts +4 -4
  39. package/src/data-structures/queue/deque.ts +10 -10
  40. package/src/data-structures/queue/queue.ts +1 -1
  41. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  42. package/src/types/data-structures/heap/heap.ts +1 -1
  43. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  44. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +2 -2
  45. 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
- // * 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
- // /**
313
- // * Time Complexity: O(log n) - Average case for a balanced tree.
314
- // * Space Complexity: O(1) - Constant space is used.
315
- // *
316
- // * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
317
- // * leftmost node if the comparison result is greater than.
318
- // * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
319
- // * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
320
- // * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
321
- // * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
322
- // * be performed. It can have one of the following values:
323
- // * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
324
- // * the key of the leftmost node if the comparison result is greater than, and the key of the
325
- // * rightmost node otherwise. If no node is found, it returns 0.
326
- // */
327
- // lastKey(beginRoot: BSTNodeKeyOrNode<K,N> = this.root, iterationType = this.iterationType): K {
328
- // if (this._compare(0, 1) === CP.lt) return this.getRightMost(beginRoot, iterationType)?.key ?? 0;
329
- // else if (this._compare(0, 1) === CP.gt) return this.getLeftMost(beginRoot, iterationType)?.key ?? 0;
330
- // else return this.getRightMost(beginRoot, iterationType)?.key ?? 0;
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 `popLast()` function removes and returns the value of the last node in a doubly linked list.
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
- popLast(): E | undefined;
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 `popFirst()` function removes and returns the value of the first node in a doubly linked list.
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
- popFirst(): E | undefined;
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 `popLast()` function removes and returns the value of the last node in a doubly linked list.
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
- popLast() {
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 `popFirst()` function removes and returns the value of the first node in a doubly linked list.
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
- popFirst() {
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 `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
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
- popLast(): E | undefined;
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 `popFirst()` function removes and returns the value of the first node in a linked list.
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
- popFirst(): E | undefined;
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 `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
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
- popLast() {
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 `popFirst()` function removes and returns the value of the first node in a linked list.
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
- popFirst() {
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 "popLast" removes and returns the last element of an array.
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
- popLast(): E | undefined;
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 "popFirst" removes and returns the first element of an array.
88
- * @returns The method `popFirst()` is returning the first element of the array after removing it
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
- popFirst(): E | undefined;
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 `popFirst()` removes and returns the first element in a data structure.
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
- popFirst(): E | undefined;
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 `popLast()` function removes and returns the last element in a data structure.
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
- popLast(): E | undefined;
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 "popLast" removes and returns the last element of an array.
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
- popLast() {
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 "popFirst" removes and returns the first element of an array.
134
- * @returns The method `popFirst()` is returning the first element of the array after removing it
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
- popFirst() {
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 `popFirst()` removes and returns the first element in a data structure.
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
- popFirst() {
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 `popLast()` function removes and returns the last element in a data structure.
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
- popLast() {
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 `popLast()` function removes and returns the value of the last element in a linked list, updating the head and tail
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
- popLast() {
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 `popFirst()` function removes and returns the value of the first node in a linked list.
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
- popFirst() {
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 `popLast()` function removes and returns the value of the last node in a doubly linked list.
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
- popLast() {
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 `popFirst()` function removes and returns the value of the first node in a doubly linked list.
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
- popFirst() {
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 "popLast" removes and returns the last element of an array.
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
- popLast() {
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 "popFirst" removes and returns the first element of an array.
3717
- * @returns The method `popFirst()` is returning the first element of the array after removing it
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
- popFirst() {
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 `popFirst()` removes and returns the first element in a data structure.
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
- popFirst() {
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 `popLast()` function removes and returns the last element in a data structure.
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
- popLast() {
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
- // * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
9391
- // * Space Complexity: O(n) - Additional space is required for the sorted array.
9392
- // */
9393
- //
9394
- // /**
9395
- // * Time Complexity: O(log n) - Average case for a balanced tree.
9396
- // * Space Complexity: O(1) - Constant space is used.
9397
- // *
9398
- // * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
9399
- // * leftmost node if the comparison result is greater than.
9400
- // * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
9401
- // * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
9402
- // * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
9403
- // * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
9404
- // * be performed. It can have one of the following values:
9405
- // * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
9406
- // * the key of the leftmost node if the comparison result is greater than, and the key of the
9407
- // * rightmost node otherwise. If no node is found, it returns 0.
9408
- // */
9409
- // lastKey(beginRoot: BSTNodeKeyOrNode<K,N> = this.root, iterationType = this.iterationType): K {
9410
- // if (this._compare(0, 1) === CP.lt) return this.getRightMost(beginRoot, iterationType)?.key ?? 0;
9411
- // else if (this._compare(0, 1) === CP.gt) return this.getLeftMost(beginRoot, iterationType)?.key ?? 0;
9412
- // else return this.getRightMost(beginRoot, iterationType)?.key ?? 0;
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]);