priority-queue-typed 1.46.9 → 1.47.2
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/binary-tree.d.ts +36 -4
- package/dist/data-structures/binary-tree/binary-tree.js +33 -1
- package/dist/data-structures/hash/hash-map.d.ts +27 -0
- package/dist/data-structures/hash/hash-map.js +27 -0
- 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 +37 -5
- package/src/data-structures/hash/hash-map.ts +27 -0
|
@@ -430,10 +430,42 @@ export declare class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = Binary
|
|
|
430
430
|
* by the return type of the `callback` function.
|
|
431
431
|
*/
|
|
432
432
|
morris<C extends BTNCallback<N>>(callback?: C, pattern?: DFSOrderPattern, beginRoot?: BTNKey | N | null | undefined): ReturnType<C>[];
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
433
|
+
/**
|
|
434
|
+
* The `forEach` function iterates over each entry in a tree and calls a callback function with the
|
|
435
|
+
* entry and the tree as arguments.
|
|
436
|
+
* @param callback - The callback parameter is a function that will be called for each entry in the
|
|
437
|
+
* tree. It takes two parameters: entry and tree.
|
|
438
|
+
*/
|
|
439
|
+
forEach(callback: (entry: [BTNKey, V | undefined], tree: this) => void): void;
|
|
440
|
+
/**
|
|
441
|
+
* The `filter` function creates a new tree by iterating over the entries of the current tree and
|
|
442
|
+
* adding the entries that satisfy the given predicate.
|
|
443
|
+
* @param predicate - The `predicate` parameter is a function that takes two arguments: `entry` and
|
|
444
|
+
* `tree`.
|
|
445
|
+
* @returns The `filter` method is returning a new tree object that contains only the entries that
|
|
446
|
+
* satisfy the given predicate function.
|
|
447
|
+
*/
|
|
448
|
+
filter(predicate: (entry: [BTNKey, V | undefined], tree: this) => boolean): TREE;
|
|
449
|
+
/**
|
|
450
|
+
* The `map` function creates a new tree by applying a callback function to each entry in the current
|
|
451
|
+
* tree.
|
|
452
|
+
* @param callback - The callback parameter is a function that takes two arguments: entry and tree.
|
|
453
|
+
* @returns The `map` method is returning a new tree object.
|
|
454
|
+
*/
|
|
455
|
+
map(callback: (entry: [BTNKey, V | undefined], tree: this) => V): TREE;
|
|
456
|
+
/**
|
|
457
|
+
* The `reduce` function iterates over the entries of a tree and applies a callback function to each
|
|
458
|
+
* entry, accumulating a single value.
|
|
459
|
+
* @param callback - The callback parameter is a function that takes three arguments: accumulator,
|
|
460
|
+
* entry, and tree. It is called for each entry in the tree and is used to accumulate a single value
|
|
461
|
+
* based on the logic defined in the callback function.
|
|
462
|
+
* @param {T} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
463
|
+
* is the value that will be passed as the first argument to the callback function when reducing the
|
|
464
|
+
* elements of the tree.
|
|
465
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
466
|
+
* all the entries in the tree and applying the callback function to each entry.
|
|
467
|
+
*/
|
|
468
|
+
reduce<T>(callback: (accumulator: T, entry: [BTNKey, V | undefined], tree: this) => T, initialValue: T): T;
|
|
437
469
|
/**
|
|
438
470
|
* The above function is an iterator for a binary tree that can be used to traverse the tree in
|
|
439
471
|
* either an iterative or recursive manner.
|
|
@@ -1411,11 +1411,25 @@ class BinaryTree {
|
|
|
1411
1411
|
}
|
|
1412
1412
|
return ans;
|
|
1413
1413
|
}
|
|
1414
|
+
/**
|
|
1415
|
+
* The `forEach` function iterates over each entry in a tree and calls a callback function with the
|
|
1416
|
+
* entry and the tree as arguments.
|
|
1417
|
+
* @param callback - The callback parameter is a function that will be called for each entry in the
|
|
1418
|
+
* tree. It takes two parameters: entry and tree.
|
|
1419
|
+
*/
|
|
1414
1420
|
forEach(callback) {
|
|
1415
1421
|
for (const entry of this) {
|
|
1416
1422
|
callback(entry, this);
|
|
1417
1423
|
}
|
|
1418
1424
|
}
|
|
1425
|
+
/**
|
|
1426
|
+
* The `filter` function creates a new tree by iterating over the entries of the current tree and
|
|
1427
|
+
* adding the entries that satisfy the given predicate.
|
|
1428
|
+
* @param predicate - The `predicate` parameter is a function that takes two arguments: `entry` and
|
|
1429
|
+
* `tree`.
|
|
1430
|
+
* @returns The `filter` method is returning a new tree object that contains only the entries that
|
|
1431
|
+
* satisfy the given predicate function.
|
|
1432
|
+
*/
|
|
1419
1433
|
filter(predicate) {
|
|
1420
1434
|
const newTree = this.createTree();
|
|
1421
1435
|
for (const [key, value] of this) {
|
|
@@ -1426,13 +1440,19 @@ class BinaryTree {
|
|
|
1426
1440
|
return newTree;
|
|
1427
1441
|
}
|
|
1428
1442
|
// TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
|
|
1429
|
-
// map<NV>(callback: (entry: [BTNKey, V | undefined], tree:
|
|
1443
|
+
// map<NV>(callback: (entry: [BTNKey, V | undefined], tree: this) => NV) {
|
|
1430
1444
|
// const newTree = this.createTree();
|
|
1431
1445
|
// for (const [key, value] of this) {
|
|
1432
1446
|
// newTree.add(key, callback([key, value], this));
|
|
1433
1447
|
// }
|
|
1434
1448
|
// return newTree;
|
|
1435
1449
|
// }
|
|
1450
|
+
/**
|
|
1451
|
+
* The `map` function creates a new tree by applying a callback function to each entry in the current
|
|
1452
|
+
* tree.
|
|
1453
|
+
* @param callback - The callback parameter is a function that takes two arguments: entry and tree.
|
|
1454
|
+
* @returns The `map` method is returning a new tree object.
|
|
1455
|
+
*/
|
|
1436
1456
|
map(callback) {
|
|
1437
1457
|
const newTree = this.createTree();
|
|
1438
1458
|
for (const [key, value] of this) {
|
|
@@ -1440,6 +1460,18 @@ class BinaryTree {
|
|
|
1440
1460
|
}
|
|
1441
1461
|
return newTree;
|
|
1442
1462
|
}
|
|
1463
|
+
/**
|
|
1464
|
+
* The `reduce` function iterates over the entries of a tree and applies a callback function to each
|
|
1465
|
+
* entry, accumulating a single value.
|
|
1466
|
+
* @param callback - The callback parameter is a function that takes three arguments: accumulator,
|
|
1467
|
+
* entry, and tree. It is called for each entry in the tree and is used to accumulate a single value
|
|
1468
|
+
* based on the logic defined in the callback function.
|
|
1469
|
+
* @param {T} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
1470
|
+
* is the value that will be passed as the first argument to the callback function when reducing the
|
|
1471
|
+
* elements of the tree.
|
|
1472
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
1473
|
+
* all the entries in the tree and applying the callback function to each entry.
|
|
1474
|
+
*/
|
|
1443
1475
|
reduce(callback, initialValue) {
|
|
1444
1476
|
let accumulator = initialValue;
|
|
1445
1477
|
for (const [key, value] of this) {
|
|
@@ -135,8 +135,35 @@ export declare class HashMap<K = any, V = any> {
|
|
|
135
135
|
* HashMap. It takes three arguments:
|
|
136
136
|
*/
|
|
137
137
|
forEach(callback: (element: [K, V], index: number, hashMap: HashMap<K, V>) => void): void;
|
|
138
|
+
/**
|
|
139
|
+
* The `filter` function takes a predicate function and returns a new HashMap containing only the
|
|
140
|
+
* key-value pairs that satisfy the predicate.
|
|
141
|
+
* @param predicate - The `predicate` parameter is a function that takes two arguments: `element` and
|
|
142
|
+
* `map`.
|
|
143
|
+
* @returns a new HashMap object that contains the key-value pairs from the original HashMap that
|
|
144
|
+
* satisfy the given predicate function.
|
|
145
|
+
*/
|
|
138
146
|
filter(predicate: (element: [K, V], map: HashMap<K, V>) => boolean): HashMap<K, V>;
|
|
147
|
+
/**
|
|
148
|
+
* The `map` function takes a callback function and returns a new HashMap with the values transformed
|
|
149
|
+
* by the callback.
|
|
150
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `element` and
|
|
151
|
+
* `map`.
|
|
152
|
+
* @returns a new HashMap object with the values mapped according to the provided callback function.
|
|
153
|
+
*/
|
|
139
154
|
map<NV>(callback: (element: [K, V], map: HashMap<K, V>) => NV): HashMap<K, NV>;
|
|
155
|
+
/**
|
|
156
|
+
* The `reduce` function iterates over the elements of a HashMap and applies a callback function to
|
|
157
|
+
* each element, accumulating a single value.
|
|
158
|
+
* @param callback - The callback parameter is a function that takes three arguments: accumulator,
|
|
159
|
+
* element, and map. It is called for each element in the HashMap and is used to accumulate a single
|
|
160
|
+
* result.
|
|
161
|
+
* @param {A} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
|
|
162
|
+
* is the value that will be passed as the first argument to the `callback` function when reducing
|
|
163
|
+
* the elements of the map.
|
|
164
|
+
* @returns The `reduce` function is returning the final value of the accumulator after iterating
|
|
165
|
+
* over all the elements in the HashMap and applying the callback function to each element.
|
|
166
|
+
*/
|
|
140
167
|
reduce<A>(callback: (accumulator: A, element: [K, V], map: HashMap<K, V>) => A, initialValue: A): A;
|
|
141
168
|
/**
|
|
142
169
|
* Time Complexity: O(n), where n is the number of elements in the HashMap.
|
|
@@ -277,6 +277,14 @@ class HashMap {
|
|
|
277
277
|
node = node.next;
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* The `filter` function takes a predicate function and returns a new HashMap containing only the
|
|
282
|
+
* key-value pairs that satisfy the predicate.
|
|
283
|
+
* @param predicate - The `predicate` parameter is a function that takes two arguments: `element` and
|
|
284
|
+
* `map`.
|
|
285
|
+
* @returns a new HashMap object that contains the key-value pairs from the original HashMap that
|
|
286
|
+
* satisfy the given predicate function.
|
|
287
|
+
*/
|
|
280
288
|
filter(predicate) {
|
|
281
289
|
const filteredMap = new HashMap();
|
|
282
290
|
for (const [key, value] of this) {
|
|
@@ -286,6 +294,13 @@ class HashMap {
|
|
|
286
294
|
}
|
|
287
295
|
return filteredMap;
|
|
288
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* The `map` function takes a callback function and returns a new HashMap with the values transformed
|
|
299
|
+
* by the callback.
|
|
300
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `element` and
|
|
301
|
+
* `map`.
|
|
302
|
+
* @returns a new HashMap object with the values mapped according to the provided callback function.
|
|
303
|
+
*/
|
|
289
304
|
map(callback) {
|
|
290
305
|
const mappedMap = new HashMap();
|
|
291
306
|
for (const [key, value] of this) {
|
|
@@ -294,6 +309,18 @@ class HashMap {
|
|
|
294
309
|
}
|
|
295
310
|
return mappedMap;
|
|
296
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* The `reduce` function iterates over the elements of a HashMap and applies a callback function to
|
|
314
|
+
* each element, accumulating a single value.
|
|
315
|
+
* @param callback - The callback parameter is a function that takes three arguments: accumulator,
|
|
316
|
+
* element, and map. It is called for each element in the HashMap and is used to accumulate a single
|
|
317
|
+
* result.
|
|
318
|
+
* @param {A} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
|
|
319
|
+
* is the value that will be passed as the first argument to the `callback` function when reducing
|
|
320
|
+
* the elements of the map.
|
|
321
|
+
* @returns The `reduce` function is returning the final value of the accumulator after iterating
|
|
322
|
+
* over all the elements in the HashMap and applying the callback function to each element.
|
|
323
|
+
*/
|
|
297
324
|
reduce(callback, initialValue) {
|
|
298
325
|
let accumulator = initialValue;
|
|
299
326
|
for (const element of this) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "priority-queue-typed",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.47.2",
|
|
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.
|
|
123
|
+
"data-structure-typed": "^1.47.2"
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -53,7 +53,7 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
|
|
|
53
53
|
return new AVLTreeNode<V, N>(key, value) as N;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
override createTree(options?: AVLTreeOptions) {
|
|
56
|
+
override createTree(options?: AVLTreeOptions): TREE {
|
|
57
57
|
return new AVLTree<V, N, TREE>({ ...this.options, ...options }) as TREE;
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -1700,13 +1700,27 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
|
|
|
1700
1700
|
return ans;
|
|
1701
1701
|
}
|
|
1702
1702
|
|
|
1703
|
-
|
|
1703
|
+
/**
|
|
1704
|
+
* The `forEach` function iterates over each entry in a tree and calls a callback function with the
|
|
1705
|
+
* entry and the tree as arguments.
|
|
1706
|
+
* @param callback - The callback parameter is a function that will be called for each entry in the
|
|
1707
|
+
* tree. It takes two parameters: entry and tree.
|
|
1708
|
+
*/
|
|
1709
|
+
forEach(callback: (entry: [BTNKey, V | undefined], tree: this) => void): void {
|
|
1704
1710
|
for (const entry of this) {
|
|
1705
1711
|
callback(entry, this);
|
|
1706
1712
|
}
|
|
1707
1713
|
}
|
|
1708
1714
|
|
|
1709
|
-
|
|
1715
|
+
/**
|
|
1716
|
+
* The `filter` function creates a new tree by iterating over the entries of the current tree and
|
|
1717
|
+
* adding the entries that satisfy the given predicate.
|
|
1718
|
+
* @param predicate - The `predicate` parameter is a function that takes two arguments: `entry` and
|
|
1719
|
+
* `tree`.
|
|
1720
|
+
* @returns The `filter` method is returning a new tree object that contains only the entries that
|
|
1721
|
+
* satisfy the given predicate function.
|
|
1722
|
+
*/
|
|
1723
|
+
filter(predicate: (entry: [BTNKey, V | undefined], tree: this) => boolean) {
|
|
1710
1724
|
const newTree = this.createTree();
|
|
1711
1725
|
for (const [key, value] of this) {
|
|
1712
1726
|
if (predicate([key, value], this)) {
|
|
@@ -1717,7 +1731,7 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
|
|
|
1717
1731
|
}
|
|
1718
1732
|
|
|
1719
1733
|
// TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
|
|
1720
|
-
// map<NV>(callback: (entry: [BTNKey, V | undefined], tree:
|
|
1734
|
+
// map<NV>(callback: (entry: [BTNKey, V | undefined], tree: this) => NV) {
|
|
1721
1735
|
// const newTree = this.createTree();
|
|
1722
1736
|
// for (const [key, value] of this) {
|
|
1723
1737
|
// newTree.add(key, callback([key, value], this));
|
|
@@ -1725,7 +1739,13 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
|
|
|
1725
1739
|
// return newTree;
|
|
1726
1740
|
// }
|
|
1727
1741
|
|
|
1728
|
-
|
|
1742
|
+
/**
|
|
1743
|
+
* The `map` function creates a new tree by applying a callback function to each entry in the current
|
|
1744
|
+
* tree.
|
|
1745
|
+
* @param callback - The callback parameter is a function that takes two arguments: entry and tree.
|
|
1746
|
+
* @returns The `map` method is returning a new tree object.
|
|
1747
|
+
*/
|
|
1748
|
+
map(callback: (entry: [BTNKey, V | undefined], tree: this) => V) {
|
|
1729
1749
|
const newTree = this.createTree();
|
|
1730
1750
|
for (const [key, value] of this) {
|
|
1731
1751
|
newTree.add(key, callback([key, value], this));
|
|
@@ -1733,7 +1753,19 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
|
|
|
1733
1753
|
return newTree;
|
|
1734
1754
|
}
|
|
1735
1755
|
|
|
1736
|
-
|
|
1756
|
+
/**
|
|
1757
|
+
* The `reduce` function iterates over the entries of a tree and applies a callback function to each
|
|
1758
|
+
* entry, accumulating a single value.
|
|
1759
|
+
* @param callback - The callback parameter is a function that takes three arguments: accumulator,
|
|
1760
|
+
* entry, and tree. It is called for each entry in the tree and is used to accumulate a single value
|
|
1761
|
+
* based on the logic defined in the callback function.
|
|
1762
|
+
* @param {T} initialValue - The initialValue parameter is the initial value of the accumulator. It
|
|
1763
|
+
* is the value that will be passed as the first argument to the callback function when reducing the
|
|
1764
|
+
* elements of the tree.
|
|
1765
|
+
* @returns The `reduce` method is returning the final value of the accumulator after iterating over
|
|
1766
|
+
* all the entries in the tree and applying the callback function to each entry.
|
|
1767
|
+
*/
|
|
1768
|
+
reduce<T>(callback: (accumulator: T, entry: [BTNKey, V | undefined], tree: this) => T, initialValue: T): T {
|
|
1737
1769
|
let accumulator = initialValue;
|
|
1738
1770
|
for (const [key, value] of this) {
|
|
1739
1771
|
accumulator = callback(accumulator, [key, value], this);
|
|
@@ -305,6 +305,14 @@ export class HashMap<K = any, V = any> {
|
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
+
/**
|
|
309
|
+
* The `filter` function takes a predicate function and returns a new HashMap containing only the
|
|
310
|
+
* key-value pairs that satisfy the predicate.
|
|
311
|
+
* @param predicate - The `predicate` parameter is a function that takes two arguments: `element` and
|
|
312
|
+
* `map`.
|
|
313
|
+
* @returns a new HashMap object that contains the key-value pairs from the original HashMap that
|
|
314
|
+
* satisfy the given predicate function.
|
|
315
|
+
*/
|
|
308
316
|
filter(predicate: (element: [K, V], map: HashMap<K, V>) => boolean): HashMap<K, V> {
|
|
309
317
|
const filteredMap = new HashMap<K, V>();
|
|
310
318
|
for (const [key, value] of this) {
|
|
@@ -315,6 +323,13 @@ export class HashMap<K = any, V = any> {
|
|
|
315
323
|
return filteredMap;
|
|
316
324
|
}
|
|
317
325
|
|
|
326
|
+
/**
|
|
327
|
+
* The `map` function takes a callback function and returns a new HashMap with the values transformed
|
|
328
|
+
* by the callback.
|
|
329
|
+
* @param callback - The `callback` parameter is a function that takes two arguments: `element` and
|
|
330
|
+
* `map`.
|
|
331
|
+
* @returns a new HashMap object with the values mapped according to the provided callback function.
|
|
332
|
+
*/
|
|
318
333
|
map<NV>(callback: (element: [K, V], map: HashMap<K, V>) => NV): HashMap<K, NV> {
|
|
319
334
|
const mappedMap = new HashMap<K, NV>();
|
|
320
335
|
for (const [key, value] of this) {
|
|
@@ -324,6 +339,18 @@ export class HashMap<K = any, V = any> {
|
|
|
324
339
|
return mappedMap;
|
|
325
340
|
}
|
|
326
341
|
|
|
342
|
+
/**
|
|
343
|
+
* The `reduce` function iterates over the elements of a HashMap and applies a callback function to
|
|
344
|
+
* each element, accumulating a single value.
|
|
345
|
+
* @param callback - The callback parameter is a function that takes three arguments: accumulator,
|
|
346
|
+
* element, and map. It is called for each element in the HashMap and is used to accumulate a single
|
|
347
|
+
* result.
|
|
348
|
+
* @param {A} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
|
|
349
|
+
* is the value that will be passed as the first argument to the `callback` function when reducing
|
|
350
|
+
* the elements of the map.
|
|
351
|
+
* @returns The `reduce` function is returning the final value of the accumulator after iterating
|
|
352
|
+
* over all the elements in the HashMap and applying the callback function to each element.
|
|
353
|
+
*/
|
|
327
354
|
reduce<A>(callback: (accumulator: A, element: [K, V], map: HashMap<K, V>) => A, initialValue: A): A {
|
|
328
355
|
let accumulator = initialValue;
|
|
329
356
|
for (const element of this) {
|