diff --git a/CHANGELOG.md b/CHANGELOG.md index 97ff15e..8dbab93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - [Semantic Versioning](https://semver.org/spec/v2.0.0.html) - [`auto-changelog`](https://github.com/CookPete/auto-changelog) -## [v1.34.7](https://github.com/zrwusa/data-structure-typed/compare/v1.34.1...main) (upcoming) +## [v1.34.8](https://github.com/zrwusa/data-structure-typed/compare/v1.34.1...main) (upcoming) ## [v1.34.1](https://github.com/zrwusa/data-structure-typed/compare/v1.33.4...v1.34.1) (6 October 2023) diff --git a/package.json b/package.json index 65fc70f..a2c2188 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.34.7", + "version": "1.34.8", "description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.", "main": "dist/index.js", "module": "lib/index.js", diff --git a/rename_clear_files.sh b/scripts/rename_clear_files.sh similarity index 100% rename from rename_clear_files.sh rename to scripts/rename_clear_files.sh diff --git a/src/data-structures/binary-tree/abstract-binary-tree.ts b/src/data-structures/binary-tree/abstract-binary-tree.ts index e2c05dc..4beedca 100644 --- a/src/data-structures/binary-tree/abstract-binary-tree.ts +++ b/src/data-structures/binary-tree/abstract-binary-tree.ts @@ -239,14 +239,14 @@ export abstract class AbstractBinaryTree { const queue: Array = [root]; while (queue.length > 0) { @@ -264,17 +264,17 @@ export abstract class AbstractBinaryTree = BSTNode> extends BinaryTree /** * The `add` function adds a new node to a binary search tree, either by creating a new node or by updating an existing * node with the same ID. - * @param {BinaryTreeNodeKey | N | null} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` + * @param {BinaryTreeNodeKey | N | null} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` * (which represents a binary tree node) or `null`. * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the new node * being added to the binary search tree. * @returns The function `add` returns the inserted node (`inserted`) which can be of type `N`, `null`, or `undefined`. */ - override add(idOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined { + override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined { // TODO support node as a param let inserted: N | null = null; let newNode: N | null = null; - if (idOrNode instanceof BSTNode) { - newNode = idOrNode; - } else if (typeof idOrNode === 'number') { - newNode = this.createNode(idOrNode, val); - } else if (idOrNode === null) { + if (keyOrNode instanceof BSTNode) { + newNode = keyOrNode; + } else if (typeof keyOrNode === 'number') { + newNode = this.createNode(keyOrNode, val); + } else if (keyOrNode === null) { newNode = null; } if (this.root === null) { @@ -152,13 +152,13 @@ export class BST = BSTNode> extends BinaryTree const combinedArr: [BinaryTreeNodeKey | N, N['val']][] = idsOrNodes.map((value, index) => [value, data?.[index]]); let sorted = []; function isNodeOrNullTuple(arr: [BinaryTreeNodeKey | N, N['val']][]): arr is [N, N['val']][] { - for (const [idOrNode] of arr) if (idOrNode instanceof BSTNode) return true; + for (const [keyOrNode] of arr) if (keyOrNode instanceof BSTNode) return true; return false; } function isBinaryTreeKeyOrNullTuple( arr: [BinaryTreeNodeKey | N, N['val']][] ): arr is [BinaryTreeNodeKey, N['val']][] { - for (const [idOrNode] of arr) if (typeof idOrNode === 'number') return true; + for (const [keyOrNode] of arr) if (typeof keyOrNode === 'number') return true; return false; } let sortedKeysOrNodes: (number | N | null)[] = [], @@ -171,7 +171,7 @@ export class BST = BSTNode> extends BinaryTree } else { throw new Error('Invalid input idsOrNodes'); } - sortedKeysOrNodes = sorted.map(([idOrNode]) => idOrNode); + sortedKeysOrNodes = sorted.map(([keyOrNode]) => keyOrNode); sortedData = sorted.map(([, val]) => val); const recursive = (arr: (BinaryTreeNodeKey | null | N)[], data?: N['val'][]) => { if (arr.length === 0) return; diff --git a/src/data-structures/binary-tree/rb-tree.ts b/src/data-structures/binary-tree/rb-tree.ts index 46e517d..1e32863 100644 --- a/src/data-structures/binary-tree/rb-tree.ts +++ b/src/data-structures/binary-tree/rb-tree.ts @@ -31,8 +31,8 @@ export class RBTree = RBTreeNode> extends BST< return new RBTreeNode(key, val) as N; } - // override add(idOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined { - // const inserted = super.add(idOrNode, val); + // override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val']): N | null | undefined { + // const inserted = super.add(keyOrNode, val); // if (inserted) this._fixInsertViolation(inserted); // return inserted; // } diff --git a/src/data-structures/binary-tree/tree-multiset.ts b/src/data-structures/binary-tree/tree-multiset.ts index 6c9e41a..098934f 100644 --- a/src/data-structures/binary-tree/tree-multiset.ts +++ b/src/data-structures/binary-tree/tree-multiset.ts @@ -106,23 +106,23 @@ export class TreeMultiset = TreeMultiset /** * The `add` function adds a new node to a binary search tree, maintaining the tree's properties and balancing if * necessary. - * @param {BinaryTreeNodeKey | N} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` (which + * @param {BinaryTreeNodeKey | N} keyOrNode - The `keyOrNode` parameter can be either a `BinaryTreeNodeKey` or a `N` (which * represents a `BinaryTreeNode`). * @param [val] - The `val` parameter represents the value to be added to the binary tree node. * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the * value should be added to the binary tree. If the `count` parameter is not provided, it defaults to 1. * @returns The method `add` returns either the inserted node (`N`), `null`, or `undefined`. */ - override add(idOrNode: BinaryTreeNodeKey | N | null, val?: N['val'], count?: number): N | null | undefined { + override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val'], count?: number): N | null | undefined { count = count ?? 1; let inserted: N | null | undefined = undefined, newNode: N | null; - if (idOrNode instanceof TreeMultisetNode) { - newNode = this.createNode(idOrNode.key, idOrNode.val, idOrNode.count); - } else if (idOrNode === null) { + if (keyOrNode instanceof TreeMultisetNode) { + newNode = this.createNode(keyOrNode.key, keyOrNode.val, keyOrNode.count); + } else if (keyOrNode === null) { newNode = null; } else { - newNode = this.createNode(idOrNode, val, count); + newNode = this.createNode(keyOrNode, val, count); } if (!this.root) { this._setRoot(newNode); @@ -222,7 +222,7 @@ export class TreeMultiset = TreeMultiset * @param {(BinaryTreeNodeKey | null)[] | (N | null)[]} idsOrNodes - An array of BinaryTreeNodeKey or BinaryTreeNode * objects, or null values. * @param {N['val'][]} [data] - The `data` parameter is an optional array of values (`N['val'][]`) that corresponds to - * the nodes being added. It is used when adding nodes using the `idOrNode` and `data` arguments in the `this.add()` + * the nodes being added. It is used when adding nodes using the `keyOrNode` and `data` arguments in the `this.add()` * method. If provided, the `data` array should * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values. */ @@ -233,19 +233,19 @@ export class TreeMultiset = TreeMultiset const inserted: (N | null | undefined)[] = []; for (let i = 0; i < idsOrNodes.length; i++) { - const idOrNode = idsOrNodes[i]; + const keyOrNode = idsOrNodes[i]; - if (idOrNode instanceof TreeMultisetNode) { - inserted.push(this.add(idOrNode.key, idOrNode.val, idOrNode.count)); + if (keyOrNode instanceof TreeMultisetNode) { + inserted.push(this.add(keyOrNode.key, keyOrNode.val, keyOrNode.count)); continue; } - if (idOrNode === null) { + if (keyOrNode === null) { inserted.push(this.add(NaN, null, 0)); continue; } - inserted.push(this.add(idOrNode, data?.[i], 1)); + inserted.push(this.add(keyOrNode, data?.[i], 1)); } return inserted; } diff --git a/src/data-structures/graph/abstract-graph.ts b/src/data-structures/graph/abstract-graph.ts index 16aca45..23f690f 100644 --- a/src/data-structures/graph/abstract-graph.ts +++ b/src/data-structures/graph/abstract-graph.ts @@ -169,11 +169,11 @@ export abstract class AbstractGraph< addVertex(key: VertexKey, val?: V['val']): boolean; - addVertex(idOrVertex: VertexKey | V, val?: V['val']): boolean { - if (idOrVertex instanceof AbstractVertex) { - return this._addVertexOnly(idOrVertex); + addVertex(keyOrVertex: VertexKey | V, val?: V['val']): boolean { + if (keyOrVertex instanceof AbstractVertex) { + return this._addVertexOnly(keyOrVertex); } else { - const newVertex = this.createVertex(idOrVertex, val); + const newVertex = this.createVertex(keyOrVertex, val); return this._addVertexOnly(newVertex); } }