From 836927ab82b35eeea2be8104e34dd8d8ee375efc Mon Sep 17 00:00:00 2001 From: Revone Date: Wed, 11 Oct 2023 18:44:59 +0800 Subject: [PATCH] [core] To compile a CommonJS module in the "dist" directory into ES6 code. Fixing some missing bugs in overloaded methods. --- .eslintrc.js | 1 + CONTRIBUTING.md | 0 .../binary-tree/abstract-binary-tree.ts | 45 ++++++++++++++++--- src/data-structures/binary-tree/bst.ts | 4 +- .../binary-tree/tree-multiset.ts | 6 +-- src/interfaces/abstract-binary-tree.ts | 13 +++--- .../data-structures/abstract-binary-tree.ts | 1 - tsconfig.prod.json | 2 +- 8 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/.eslintrc.js b/.eslintrc.js index db5f307..8a44df5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,6 +3,7 @@ module.exports = { "plugin:@typescript-eslint/recommended", "prettier" ], + ignorePatterns: ["lib/", "dist/", "umd/", "coverage/", "docs/"], "rules": { "import/no-anonymous-default-export": "off", "@typescript-eslint/no-unused-vars": "error", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e69de29 diff --git a/src/data-structures/binary-tree/abstract-binary-tree.ts b/src/data-structures/binary-tree/abstract-binary-tree.ts index 1aad936..6e5a345 100644 --- a/src/data-structures/binary-tree/abstract-binary-tree.ts +++ b/src/data-structures/binary-tree/abstract-binary-tree.ts @@ -477,7 +477,7 @@ export abstract class AbstractBinaryTree objects. + */ + listLevels(): BinaryTreeNodeKey[][]; + /** * Collects nodes from a binary tree by a specified property and organizes them into levels. * @param {N | null} node - The root node of the binary tree or null. If null, the function will use the root node of the current binary tree instance. @@ -1244,6 +1270,13 @@ export abstract class AbstractBinaryTree = BSTNode> extends BinaryTree override getNodes( nodeProperty: BinaryTreeNodeKey | N, propertyName: BinaryTreeNodePropertyName = 'key', - onlyOne: boolean = false + onlyOne = false ): N[] { if (!this.root) return []; const result: N[] = []; @@ -526,7 +526,7 @@ export class BST = BSTNode> extends BinaryTree /** * The function compares two binary tree node IDs using a comparator function and returns whether the first ID is * greater than, less than, or equal to the second ID. - * @param {BinaryTreeNodeKey} a - a is a BinaryTreeNodeKey, which represents the identifier of a binary tree node. + * @param {BinaryTreeNodeKey} a - "a" is a BinaryTreeNodeKey, which represents the identifier of a binary tree node. * @param {BinaryTreeNodeKey} b - The parameter "b" in the above code refers to a BinaryTreeNodeKey. * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater than), CP.lt (less * than), or CP.eq (equal). diff --git a/src/data-structures/binary-tree/tree-multiset.ts b/src/data-structures/binary-tree/tree-multiset.ts index 48a989a..e962e37 100644 --- a/src/data-structures/binary-tree/tree-multiset.ts +++ b/src/data-structures/binary-tree/tree-multiset.ts @@ -105,7 +105,7 @@ export class TreeMultiset = TreeMultiset * 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(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val'], count: number = 1): N | null | undefined { + override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: N['val'], count = 1): N | null | undefined { let inserted: N | null | undefined = undefined, newNode: N | null; if (keyOrNode instanceof TreeMultisetNode) { @@ -293,7 +293,7 @@ export class TreeMultiset = TreeMultiset * not be taken into account when removing it. If `ignoreCount` is set to `false * @returns The function `remove` returns an array of `BinaryTreeDeletedResult` objects. */ - override remove(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount: boolean = false): BinaryTreeDeletedResult[] { + override remove(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount = false): BinaryTreeDeletedResult[] { const bstDeletedResult: BinaryTreeDeletedResult[] = []; if (!this.root) return bstDeletedResult; @@ -474,7 +474,7 @@ export class TreeMultiset = TreeMultiset * to `true`, the function will return only one node. If `onlyOne` * @returns an array of nodes that match the given nodeProperty. */ - getNodesByCount(nodeProperty: BinaryTreeNodeKey | N, onlyOne: boolean = false): N[] { + getNodesByCount(nodeProperty: BinaryTreeNodeKey | N, onlyOne = false): N[] { if (!this.root) return []; const result: N[] = []; diff --git a/src/interfaces/abstract-binary-tree.ts b/src/interfaces/abstract-binary-tree.ts index c7ff20c..e39f6da 100644 --- a/src/interfaces/abstract-binary-tree.ts +++ b/src/interfaces/abstract-binary-tree.ts @@ -124,18 +124,15 @@ export interface IAbstractBinaryTree; + dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties; levelIterative(node: N | null): BinaryTreeNodeKey[]; diff --git a/src/types/data-structures/abstract-binary-tree.ts b/src/types/data-structures/abstract-binary-tree.ts index f214b97..039098a 100644 --- a/src/types/data-structures/abstract-binary-tree.ts +++ b/src/types/data-structures/abstract-binary-tree.ts @@ -12,7 +12,6 @@ export enum LoopType { RECURSIVE = 'RECURSIVE' } -/* This enumeration defines the position of a node within a family tree composed of three associated nodes, where 'root' represents the root node of the family tree, 'left' represents the left child node, and 'right' represents the right child node. */ export enum FamilyPosition { ROOT = 'ROOT', LEFT = 'LEFT', diff --git a/tsconfig.prod.json b/tsconfig.prod.json index b3c3840..f0b1573 100644 --- a/tsconfig.prod.json +++ b/tsconfig.prod.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES5", + "target": "ES6", "module": "CommonJS", "outDir": "./dist", "sourceMap": true,