priority-queue-typed 1.46.9 → 1.47.1

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.
@@ -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
- forEach(callback: (entry: [BTNKey, V | undefined], tree: typeof this) => void): void;
434
- filter(predicate: (entry: [BTNKey, V | undefined], tree: typeof this) => boolean): TREE;
435
- map(callback: (entry: [BTNKey, V | undefined], tree: typeof this) => V): TREE;
436
- reduce<T>(callback: (accumulator: T, entry: [BTNKey, V | undefined], tree: typeof this) => T, initialValue: T): T;
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: typeof this) => NV) {
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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "priority-queue-typed",
3
- "version": "1.46.9",
3
+ "version": "1.47.1",
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.46.9"
123
+ "data-structure-typed": "^1.47.1"
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
- forEach(callback: (entry: [BTNKey, V | undefined], tree: typeof this) => void): void {
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
- filter(predicate: (entry: [BTNKey, V | undefined], tree: typeof this) => boolean) {
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: typeof this) => NV) {
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
- map(callback: (entry: [BTNKey, V | undefined], tree: typeof this) => V) {
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
- reduce<T>(callback: (accumulator: T, entry: [BTNKey, V | undefined], tree: typeof this) => T, initialValue: T): T {
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);