data-structure-typed 1.46.9 → 1.47.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "1.46.9",
3
+ "version": "1.47.0",
4
4
  "description": "Data Structures of Javascript & TypeScript. Heap, Binary Tree, RedBlack Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack.",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/mjs/index.js",
@@ -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);