[core] To compile a CommonJS module in the "dist" directory into ES6 code. Fixing some missing bugs in overloaded methods.

This commit is contained in:
Revone 2023-10-11 18:44:59 +08:00
parent 8b9ef598e5
commit 836927ab82
8 changed files with 51 additions and 21 deletions

View file

@ -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",

0
CONTRIBUTING.md Normal file
View file

View file

@ -477,7 +477,7 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
getNodes(
nodeProperty: BinaryTreeNodeKey | N,
propertyName: BinaryTreeNodePropertyName = 'key',
onlyOne: boolean = false
onlyOne = false
): N[] {
if (!this.root) return [];
@ -908,6 +908,13 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
*/
dfs(): BinaryTreeNodeKey[];
/**
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @returns An array of values corresponding to the specified property.
*/
dfs(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
/**
* Performs a depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
@ -976,6 +983,13 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
*/
dfsIterative(): BinaryTreeNodeKey[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on their 'key' property.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @returns An array of values corresponding to the specified property.
*/
dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates properties of each node based on the specified property name.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
@ -990,7 +1004,7 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
* @param {'val'} nodeOrPropertyName - The name of the property to accumulate.
* @returns An array of 'val' properties from each node.
*/
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N[];
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
/**
* Performs an iterative depth-first search (dfs) traversal on a binary tree and accumulates nodes themselves.
@ -1050,6 +1064,12 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
return this._getResultByPropertyName(nodeOrPropertyName);
}
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
* @returns An array of binary tree node IDs.
*/
levelIterative(): BinaryTreeNodeKey[];
/**
* Performs a level-order traversal on a binary tree starting from the specified node and accumulates properties of each node based on their 'key' property.
* @param {N | null} node - The starting node for the level order traversal. If null, the root node of the tree is used as the starting node.
@ -1118,6 +1138,12 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
return this._getResultByPropertyName(nodeOrPropertyName);
}
/**
* Collects nodes from a binary tree by a specified property and organizes them into levels.
* @returns A 2D array of AbstractBinaryTreeNodeProperty<N> 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<N extends AbstractBinaryTreeNode<N['val
*/
morris(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
/**
* Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates properties of each node based on the specified property name.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
* @returns An array of values corresponding to the specified property.
*/
morris(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
/**
* Performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris traversal algorithm and accumulates the 'val' property of each node.
* @param {'in' | 'pre' | 'post'} [pattern] - The traversal pattern: 'in' (in-order), 'pre' (pre-order), or 'post' (post-order).
@ -1444,25 +1477,25 @@ export abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val
result: (N | null | undefined)[],
nodeProperty: BinaryTreeNodeKey | N,
propertyName: BinaryTreeNodePropertyName = 'key',
onlyOne: boolean = false
onlyOne = false
) {
switch (propertyName) {
case 'key':
if (cur.key === nodeProperty) {
result.push(cur);
return !!onlyOne;
return onlyOne;
}
break;
case 'val':
if (cur.val === nodeProperty) {
result.push(cur);
return !!onlyOne;
return onlyOne;
}
break;
default:
if (cur.key === nodeProperty) {
result.push(cur);
return !!onlyOne;
return onlyOne;
}
break;
}

View file

@ -247,7 +247,7 @@ export class BST<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
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<N extends BSTNode<N['val'], N> = BSTNode> extends BinaryTree<N>
/**
* 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).

View file

@ -105,7 +105,7 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = 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<N extends TreeMultisetNode<N['val'], N> = TreeMultiset
* not be taken into account when removing it. If `ignoreCount` is set to `false
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
*/
override remove(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount: boolean = false): BinaryTreeDeletedResult<N>[] {
override remove(nodeOrKey: N | BinaryTreeNodeKey, ignoreCount = false): BinaryTreeDeletedResult<N>[] {
const bstDeletedResult: BinaryTreeDeletedResult<N>[] = [];
if (!this.root) return bstDeletedResult;
@ -474,7 +474,7 @@ export class TreeMultiset<N extends TreeMultisetNode<N['val'], N> = 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[] = [];

View file

@ -124,18 +124,15 @@ export interface IAbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'],
dfsIterative(): BinaryTreeNodeKey[];
dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'key'): BinaryTreeNodeKey[];
dfsIterative(pattern: DFSOrderPattern): BinaryTreeNodeKey[];
dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'key'): BinaryTreeNodeKey[];
dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'val'): N['val'][];
dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
dfsIterative(pattern: DFSOrderPattern, nodeOrPropertyName: 'node'): N[];
dfsIterative(
pattern?: 'in' | 'pre' | 'post',
nodeOrPropertyName?: NodeOrPropertyName
): AbstractBinaryTreeNodeProperties<N>;
dfsIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
levelIterative(node: N | null): BinaryTreeNodeKey[];

View file

@ -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',

View file

@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES5",
"target": "ES6",
"module": "CommonJS",
"outDir": "./dist",
"sourceMap": true,