priority-queue-typed 1.49.5 → 1.49.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/dist/data-structures/binary-tree/avl-tree.d.ts +53 -48
- package/dist/data-structures/binary-tree/avl-tree.js +55 -49
- package/dist/data-structures/binary-tree/binary-tree.d.ts +153 -130
- package/dist/data-structures/binary-tree/binary-tree.js +194 -153
- package/dist/data-structures/binary-tree/bst.d.ts +83 -71
- package/dist/data-structures/binary-tree/bst.js +114 -91
- package/dist/data-structures/binary-tree/rb-tree.d.ts +37 -35
- package/dist/data-structures/binary-tree/rb-tree.js +62 -59
- package/dist/data-structures/binary-tree/tree-multimap.d.ts +46 -39
- package/dist/data-structures/binary-tree/tree-multimap.js +58 -51
- package/dist/data-structures/hash/hash-map.d.ts +24 -27
- package/dist/data-structures/hash/hash-map.js +35 -35
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -1
- package/dist/data-structures/heap/heap.d.ts +2 -1
- package/dist/data-structures/heap/heap.js +13 -13
- package/dist/data-structures/heap/max-heap.js +1 -1
- package/dist/data-structures/heap/min-heap.js +1 -1
- package/dist/data-structures/linked-list/doubly-linked-list.js +1 -1
- package/dist/data-structures/linked-list/singly-linked-list.js +1 -3
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -8
- package/dist/data-structures/linked-list/skip-linked-list.js +15 -18
- package/dist/data-structures/matrix/matrix.d.ts +2 -7
- package/dist/data-structures/matrix/matrix.js +0 -7
- package/dist/data-structures/priority-queue/max-priority-queue.js +1 -1
- package/dist/data-structures/priority-queue/min-priority-queue.js +1 -1
- package/dist/data-structures/priority-queue/priority-queue.js +1 -1
- package/dist/data-structures/queue/deque.d.ts +2 -11
- package/dist/data-structures/queue/deque.js +9 -13
- package/dist/data-structures/queue/queue.d.ts +13 -13
- package/dist/data-structures/queue/queue.js +29 -25
- package/dist/data-structures/stack/stack.js +2 -3
- package/dist/data-structures/trie/trie.d.ts +2 -2
- package/dist/data-structures/trie/trie.js +9 -5
- package/dist/interfaces/binary-tree.d.ts +3 -3
- package/dist/types/common.d.ts +3 -3
- package/dist/types/common.js +2 -2
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +2 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multimap.d.ts +1 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +5 -2
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/hash/index.js +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/types/data-structures/linked-list/index.d.ts +1 -0
- package/dist/types/data-structures/linked-list/index.js +1 -0
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +4 -1
- package/dist/types/data-structures/matrix/index.d.ts +1 -0
- package/dist/types/data-structures/matrix/index.js +1 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +7 -1
- package/dist/types/data-structures/queue/deque.d.ts +3 -1
- package/dist/types/data-structures/trie/trie.d.ts +3 -1
- package/package.json +2 -2
- package/src/data-structures/binary-tree/avl-tree.ts +58 -53
- package/src/data-structures/binary-tree/binary-tree.ts +255 -211
- package/src/data-structures/binary-tree/bst.ts +126 -107
- package/src/data-structures/binary-tree/rb-tree.ts +66 -64
- package/src/data-structures/binary-tree/tree-multimap.ts +62 -56
- package/src/data-structures/hash/hash-map.ts +46 -50
- package/src/data-structures/hash/index.ts +0 -1
- package/src/data-structures/heap/heap.ts +20 -19
- package/src/data-structures/heap/max-heap.ts +1 -1
- package/src/data-structures/heap/min-heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -5
- package/src/data-structures/linked-list/skip-linked-list.ts +15 -16
- package/src/data-structures/matrix/matrix.ts +2 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/data-structures/queue/deque.ts +11 -15
- package/src/data-structures/queue/queue.ts +29 -28
- package/src/data-structures/stack/stack.ts +3 -6
- package/src/data-structures/trie/trie.ts +10 -11
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/common.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multimap.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +6 -2
- package/src/types/data-structures/hash/index.ts +0 -1
- package/src/types/data-structures/heap/heap.ts +1 -1
- package/src/types/data-structures/linked-list/index.ts +1 -0
- package/src/types/data-structures/linked-list/skip-linked-list.ts +1 -1
- package/src/types/data-structures/matrix/index.ts +1 -0
- package/src/types/data-structures/matrix/matrix.ts +7 -1
- package/src/types/data-structures/queue/deque.ts +1 -1
- package/src/types/data-structures/trie/trie.ts +1 -1
- package/dist/data-structures/hash/hash-table.d.ts +0 -108
- package/dist/data-structures/hash/hash-table.js +0 -281
- package/dist/types/data-structures/hash/hash-table.d.ts +0 -1
- package/dist/types/data-structures/hash/hash-table.js +0 -2
- package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -1
- package/dist/types/data-structures/matrix/matrix2d.js +0 -2
- package/dist/types/data-structures/matrix/vector2d.d.ts +0 -1
- package/dist/types/data-structures/matrix/vector2d.js +0 -2
- package/src/data-structures/hash/hash-table.ts +0 -318
- package/src/types/data-structures/hash/hash-table.ts +0 -1
- package/src/types/data-structures/matrix/matrix2d.ts +0 -1
- package/src/types/data-structures/matrix/vector2d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "priority-queue-typed",
|
|
3
|
-
"version": "1.49.
|
|
3
|
+
"version": "1.49.7",
|
|
4
4
|
"description": "Priority Queue, Min Priority Queue, Max Priority Queue. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -120,6 +120,6 @@
|
|
|
120
120
|
"typedoc": "^0.25.1"
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
|
-
"data-structure-typed": "^1.49.
|
|
123
|
+
"data-structure-typed": "^1.49.7"
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -13,8 +13,7 @@ import type {
|
|
|
13
13
|
BinaryTreeDeleteResult,
|
|
14
14
|
BSTNKeyOrNode,
|
|
15
15
|
BTNCallback,
|
|
16
|
-
|
|
17
|
-
BTNKeyOrNode
|
|
16
|
+
KeyOrNodeOrEntry
|
|
18
17
|
} from '../../types';
|
|
19
18
|
import { IBinaryTree } from '../../interfaces';
|
|
20
19
|
|
|
@@ -49,17 +48,17 @@ export class AVLTree<
|
|
|
49
48
|
extends BST<K, V, N, TREE>
|
|
50
49
|
implements IBinaryTree<K, V, N, TREE> {
|
|
51
50
|
/**
|
|
52
|
-
* The constructor function initializes an AVLTree object with optional
|
|
53
|
-
* @param [
|
|
54
|
-
* objects. It represents a collection of
|
|
51
|
+
* The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
|
|
52
|
+
* @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
|
|
53
|
+
* objects. It represents a collection of nodes that will be added to the AVL tree during
|
|
55
54
|
* initialization.
|
|
56
55
|
* @param [options] - The `options` parameter is an optional object that allows you to customize the
|
|
57
56
|
* behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
|
|
58
57
|
* provide only a subset of the properties defined in the `AVLTreeOptions` interface.
|
|
59
58
|
*/
|
|
60
|
-
constructor(
|
|
59
|
+
constructor(keysOrNodesOrEntries: Iterable<KeyOrNodeOrEntry<K, V, N>> = [], options?: AVLTreeOptions<K>) {
|
|
61
60
|
super([], options);
|
|
62
|
-
if (
|
|
61
|
+
if (keysOrNodesOrEntries) super.addMany(keysOrNodesOrEntries);
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
/**
|
|
@@ -91,12 +90,12 @@ export class AVLTree<
|
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
/**
|
|
94
|
-
* The function checks if an
|
|
95
|
-
* @param
|
|
96
|
-
* @returns a boolean value indicating whether the
|
|
93
|
+
* The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
|
|
94
|
+
* @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
|
|
95
|
+
* @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
|
|
97
96
|
*/
|
|
98
|
-
override isNode(
|
|
99
|
-
return
|
|
97
|
+
override isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N {
|
|
98
|
+
return keyOrNodeOrEntry instanceof AVLTreeNode;
|
|
100
99
|
}
|
|
101
100
|
|
|
102
101
|
/**
|
|
@@ -105,18 +104,19 @@ export class AVLTree<
|
|
|
105
104
|
* data type.
|
|
106
105
|
* @returns a boolean value indicating whether the potentialKey is of type number or not.
|
|
107
106
|
*/
|
|
108
|
-
override isNotNodeInstance(potentialKey:
|
|
107
|
+
override isNotNodeInstance(potentialKey: KeyOrNodeOrEntry<K, V, N>): potentialKey is K {
|
|
109
108
|
return !(potentialKey instanceof AVLTreeNode);
|
|
110
109
|
}
|
|
111
110
|
|
|
112
111
|
/**
|
|
113
|
-
* Time Complexity: O(log n)
|
|
114
|
-
* Space Complexity: O(1)
|
|
112
|
+
* Time Complexity: O(log n)
|
|
113
|
+
* Space Complexity: O(1)
|
|
114
|
+
* logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
|
|
115
115
|
*/
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
|
-
* Time Complexity: O(log n)
|
|
119
|
-
* Space Complexity: O(1)
|
|
118
|
+
* Time Complexity: O(log n)
|
|
119
|
+
* Space Complexity: O(1)
|
|
120
120
|
*
|
|
121
121
|
* The function overrides the add method of a binary tree node and balances the tree after inserting
|
|
122
122
|
* a new node.
|
|
@@ -126,21 +126,21 @@ export class AVLTree<
|
|
|
126
126
|
* being added to the binary tree.
|
|
127
127
|
* @returns The method is returning either the inserted node or undefined.
|
|
128
128
|
*/
|
|
129
|
-
override add(keyOrNodeOrEntry:
|
|
130
|
-
if (keyOrNodeOrEntry === null) return
|
|
129
|
+
override add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean {
|
|
130
|
+
if (keyOrNodeOrEntry === null) return false;
|
|
131
131
|
const inserted = super.add(keyOrNodeOrEntry, value);
|
|
132
|
-
if (inserted) this._balancePath(
|
|
132
|
+
if (inserted) this._balancePath(keyOrNodeOrEntry);
|
|
133
133
|
return inserted;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
|
-
* Time Complexity: O(log n)
|
|
138
|
-
* Space Complexity: O(1)
|
|
137
|
+
* Time Complexity: O(log n)
|
|
138
|
+
* Space Complexity: O(1)
|
|
139
139
|
*/
|
|
140
140
|
|
|
141
141
|
/**
|
|
142
|
-
* Time Complexity: O(log n)
|
|
143
|
-
* Space Complexity: O(1)
|
|
142
|
+
* Time Complexity: O(log n)
|
|
143
|
+
* Space Complexity: O(1)
|
|
144
144
|
*
|
|
145
145
|
* The function overrides the delete method of a binary tree, performs the deletion, and then
|
|
146
146
|
* balances the tree if necessary.
|
|
@@ -203,13 +203,14 @@ export class AVLTree<
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
|
-
* Time Complexity: O(1)
|
|
207
|
-
* Space Complexity: O(1)
|
|
206
|
+
* Time Complexity: O(1)
|
|
207
|
+
* Space Complexity: O(1)
|
|
208
|
+
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
|
|
208
209
|
*/
|
|
209
210
|
|
|
210
211
|
/**
|
|
211
|
-
* Time Complexity: O(1)
|
|
212
|
-
* Space Complexity: O(1)
|
|
212
|
+
* Time Complexity: O(1)
|
|
213
|
+
* Space Complexity: O(1)
|
|
213
214
|
*
|
|
214
215
|
* The function calculates the balance factor of a node in a binary tree.
|
|
215
216
|
* @param {N} node - The parameter "node" represents a node in a binary tree data structure.
|
|
@@ -227,13 +228,14 @@ export class AVLTree<
|
|
|
227
228
|
}
|
|
228
229
|
|
|
229
230
|
/**
|
|
230
|
-
* Time Complexity: O(1)
|
|
231
|
-
* Space Complexity: O(1)
|
|
231
|
+
* Time Complexity: O(1)
|
|
232
|
+
* Space Complexity: O(1)
|
|
233
|
+
* constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
|
|
232
234
|
*/
|
|
233
235
|
|
|
234
236
|
/**
|
|
235
|
-
* Time Complexity: O(1)
|
|
236
|
-
* Space Complexity: O(1)
|
|
237
|
+
* Time Complexity: O(1)
|
|
238
|
+
* Space Complexity: O(1)
|
|
237
239
|
*
|
|
238
240
|
* The function updates the height of a node in a binary tree based on the heights of its left and
|
|
239
241
|
* right children.
|
|
@@ -249,20 +251,22 @@ export class AVLTree<
|
|
|
249
251
|
}
|
|
250
252
|
|
|
251
253
|
/**
|
|
252
|
-
* Time Complexity: O(log n)
|
|
253
|
-
* Space Complexity: O(1)
|
|
254
|
+
* Time Complexity: O(log n)
|
|
255
|
+
* Space Complexity: O(1)
|
|
256
|
+
* logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
|
|
254
257
|
*/
|
|
255
258
|
|
|
256
259
|
/**
|
|
257
|
-
* Time Complexity: O(log n)
|
|
258
|
-
* Space Complexity: O(1)
|
|
260
|
+
* Time Complexity: O(log n)
|
|
261
|
+
* Space Complexity: O(1)
|
|
259
262
|
*
|
|
260
263
|
* The `_balancePath` function is used to update the heights of nodes and perform rotation operations
|
|
261
264
|
* to restore balance in an AVL tree after inserting a node.
|
|
262
265
|
* @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
|
|
263
266
|
* AVL tree that needs to be balanced.
|
|
264
267
|
*/
|
|
265
|
-
protected _balancePath(node: N): void {
|
|
268
|
+
protected _balancePath(node: KeyOrNodeOrEntry<K, V, N>): void {
|
|
269
|
+
node = this.ensureNode(node);
|
|
266
270
|
const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
|
|
267
271
|
for (let i = 0; i < path.length; i++) {
|
|
268
272
|
// second O(log n)
|
|
@@ -302,13 +306,14 @@ export class AVLTree<
|
|
|
302
306
|
}
|
|
303
307
|
|
|
304
308
|
/**
|
|
305
|
-
* Time Complexity: O(1)
|
|
306
|
-
* Space Complexity: O(1)
|
|
309
|
+
* Time Complexity: O(1)
|
|
310
|
+
* Space Complexity: O(1)
|
|
311
|
+
* constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
|
|
307
312
|
*/
|
|
308
313
|
|
|
309
314
|
/**
|
|
310
|
-
* Time Complexity: O(1)
|
|
311
|
-
* Space Complexity: O(1)
|
|
315
|
+
* Time Complexity: O(1)
|
|
316
|
+
* Space Complexity: O(1)
|
|
312
317
|
*
|
|
313
318
|
* The function `_balanceLL` performs a left-left rotation to balance a binary tree.
|
|
314
319
|
* @param {N} A - A is a node in a binary tree.
|
|
@@ -340,13 +345,13 @@ export class AVLTree<
|
|
|
340
345
|
}
|
|
341
346
|
|
|
342
347
|
/**
|
|
343
|
-
* Time Complexity: O(1)
|
|
344
|
-
* Space Complexity: O(1)
|
|
348
|
+
* Time Complexity: O(1)
|
|
349
|
+
* Space Complexity: O(1)
|
|
345
350
|
*/
|
|
346
351
|
|
|
347
352
|
/**
|
|
348
|
-
* Time Complexity: O(1)
|
|
349
|
-
* Space Complexity: O(1)
|
|
353
|
+
* Time Complexity: O(1)
|
|
354
|
+
* Space Complexity: O(1)
|
|
350
355
|
*
|
|
351
356
|
* The `_balanceLR` function performs a left-right rotation to balance a binary tree.
|
|
352
357
|
* @param {N} A - A is a node in a binary tree.
|
|
@@ -396,13 +401,13 @@ export class AVLTree<
|
|
|
396
401
|
}
|
|
397
402
|
|
|
398
403
|
/**
|
|
399
|
-
* Time Complexity: O(1)
|
|
400
|
-
* Space Complexity: O(1)
|
|
404
|
+
* Time Complexity: O(1)
|
|
405
|
+
* Space Complexity: O(1)
|
|
401
406
|
*/
|
|
402
407
|
|
|
403
408
|
/**
|
|
404
|
-
* Time Complexity: O(1)
|
|
405
|
-
* Space Complexity: O(1)
|
|
409
|
+
* Time Complexity: O(1)
|
|
410
|
+
* Space Complexity: O(1)
|
|
406
411
|
*
|
|
407
412
|
* The function `_balanceRR` performs a right-right rotation to balance a binary tree.
|
|
408
413
|
* @param {N} A - A is a node in a binary tree.
|
|
@@ -439,13 +444,13 @@ export class AVLTree<
|
|
|
439
444
|
}
|
|
440
445
|
|
|
441
446
|
/**
|
|
442
|
-
* Time Complexity: O(1)
|
|
443
|
-
* Space Complexity: O(1)
|
|
447
|
+
* Time Complexity: O(1)
|
|
448
|
+
* Space Complexity: O(1)
|
|
444
449
|
*/
|
|
445
450
|
|
|
446
451
|
/**
|
|
447
|
-
* Time Complexity: O(1)
|
|
448
|
-
* Space Complexity: O(1)
|
|
452
|
+
* Time Complexity: O(1)
|
|
453
|
+
* Space Complexity: O(1)
|
|
449
454
|
*
|
|
450
455
|
* The function `_balanceRL` performs a right-left rotation to balance a binary tree.
|
|
451
456
|
* @param {N} A - A is a node in a binary tree.
|