From 76db084bdad57c782e0b54b1eadb78c8e4368fa8 Mon Sep 17 00:00:00 2001 From: Revone Date: Sat, 25 Nov 2023 20:59:34 +0800 Subject: [PATCH] refactor: Explicitly call the super.addMany method. chore: reformat project configs --- .dependency-cruiser.js | 4 +- .editorconfig | 18 ++++---- .github/ISSUE_TEMPLATE/bug_report.md | 17 ++++---- .github/workflows/ci.yml | 2 +- .github/workflows/release-package.yml | 2 +- CHANGELOG.md | 28 +++++++++---- CODE_OF_CONDUCT.md | 42 ++++++++++++++----- COMMANDS.md | 4 +- CONTRIBUTING.md | 7 ++-- README.md | 28 +++++++------ SECURITY.md | 2 +- jest.config.js | 2 +- src/data-structures/binary-tree/avl-tree.ts | 2 +- .../binary-tree/binary-tree.ts | 17 +++----- src/data-structures/binary-tree/bst.ts | 1 - src/data-structures/binary-tree/rb-tree.ts | 2 +- .../{all-in-one.ts => all-in-one.test.ts} | 2 +- tsconfig-cjs.json | 2 +- 18 files changed, 108 insertions(+), 74 deletions(-) rename test/integration/{all-in-one.ts => all-in-one.test.ts} (98%) diff --git a/.dependency-cruiser.js b/.dependency-cruiser.js index 78e5afc..2c54a48 100644 --- a/.dependency-cruiser.js +++ b/.dependency-cruiser.js @@ -234,7 +234,7 @@ module.exports = { "specify": for each dependency identify whether it only exists before compilation or also after */ tsPreCompilationDeps: true, - + /* list of extensions to scan that aren't javascript or compile-to-javascript. Empty by default. Only put extensions in here that you want to take into @@ -304,7 +304,7 @@ module.exports = { If you have an `exportsFields` attribute in your webpack config, that one will have precedence over the one specified here. - */ + */ exportsFields: ["exports"], /* List of conditions to check for in the exports field. e.g. use ['imports'] if you're only interested in exposed es6 modules, ['require'] for commonjs, diff --git a/.editorconfig b/.editorconfig index 5fee044..59f5b5a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,16 +1,16 @@ # Editor configuration, see http://editorconfig.org -root=true # represents the top-level EditorConfig configuration file +root = true # represents the top-level EditorConfig configuration file -[*] # means applicable to all files -charset = utf-8 # Set the file character set to utf-8 -indent_style = space # Indent style (tab | space) -indent_size = 2 # indent size -end_of_line = lf # Control line break type (lf | cr | crlf) -trim_trailing_whitespace = true # Remove any whitespace characters at the beginning of the line -insert_final_newline = true # Always insert a new line at the end of the file +[*] # means applicable to all files +charset = utf-8 # Set the file character set to utf-8 +indent_style = space # Indent style (tab | space) +indent_size = 2 # indent size +end_of_line = lf # Control line break type (lf | cr | crlf) +trim_trailing_whitespace = true # Remove any whitespace characters at the beginning of the line +insert_final_newline = true # Always insert a new line at the end of the file -[*.md] # Indicates that only md files apply the following rules +[*.md] # Indicates that only md files apply the following rules max_line_length = off trim_trailing_whitespace = false diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dd84ea7..3205926 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -12,6 +12,7 @@ A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: + 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' @@ -24,15 +25,17 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] + +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] **Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] + +- Device: [e.g. iPhone6] +- OS: [e.g. iOS8.1] +- Browser [e.g. stock browser, safari] +- Version [e.g. 22] **Additional context** Add any other context about the problem here. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0fe17d3..9b01142 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [19.9.0] + node-version: [ 19.9.0 ] steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml index 7e485d6..4024bb5 100644 --- a/.github/workflows/release-package.yml +++ b/.github/workflows/release-package.yml @@ -2,7 +2,7 @@ name: data-structure-typed on: release: - types: [created] + types: [ created ] jobs: build: diff --git a/CHANGELOG.md b/CHANGELOG.md index 81f86ef..87cbf8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,22 +14,32 @@ All notable changes to this project will be documented in this file. - Rbtree [`#31`](https://github.com/zrwusa/data-structure-typed/pull/31) - [graph test] edge cases enriched [`#30`](https://github.com/zrwusa/data-structure-typed/pull/30) -- [graph] Modify the data structure design of the graph to change the g… [`#29`](https://github.com/zrwusa/data-structure-typed/pull/29) +- [graph] Modify the data structure design of the graph to change the + g… [`#29`](https://github.com/zrwusa/data-structure-typed/pull/29) - Optimization [`#23`](https://github.com/zrwusa/data-structure-typed/pull/23) - Optimization [`#20`](https://github.com/zrwusa/data-structure-typed/pull/20) -- [binary-tree, graph] Replace all code that uses Arrays as makeshift Q… [`#18`](https://github.com/zrwusa/data-structure-typed/pull/18) -- 1. No need for dfsIterative; integrate it directly into the dfs metho… [`#17`](https://github.com/zrwusa/data-structure-typed/pull/17) -- [heap] fibonacci heap implemented. [test] big O estimate. [project] n… [`#15`](https://github.com/zrwusa/data-structure-typed/pull/15) +- [binary-tree, graph] Replace all code that uses Arrays as makeshift + Q… [`#18`](https://github.com/zrwusa/data-structure-typed/pull/18) +- + 1. No need for dfsIterative; integrate it directly into the dfs + metho… [`#17`](https://github.com/zrwusa/data-structure-typed/pull/17) +- [heap] fibonacci heap implemented. [test] big O estimate. [project] + n… [`#15`](https://github.com/zrwusa/data-structure-typed/pull/15) - [rbtree] implemented, but with bugs [`#13`](https://github.com/zrwusa/data-structure-typed/pull/13) -- [trie] renamed ambiguous methods and add comments to all methods. [`#12`](https://github.com/zrwusa/data-structure-typed/pull/12) -- [binarytree] modified the getDepth method to adhere to the proper def… [`#11`](https://github.com/zrwusa/data-structure-typed/pull/11) +- [trie] renamed ambiguous methods and add comments to all + methods. [`#12`](https://github.com/zrwusa/data-structure-typed/pull/12) +- [binarytree] modified the getDepth method to adhere to the proper + def… [`#11`](https://github.com/zrwusa/data-structure-typed/pull/11) - Trie [`#10`](https://github.com/zrwusa/data-structure-typed/pull/10) - [tree] getHeight returns faulty height bug fixed [`#9`](https://github.com/zrwusa/data-structure-typed/pull/9) - [trie] support casesensitivity. getWords bug fixed [`#8`](https://github.com/zrwusa/data-structure-typed/pull/8) -- [binary-tree, graph] In order to optimize the design of Binary Trees,… [`#7`](https://github.com/zrwusa/data-structure-typed/pull/7) -- [BinaryTree, Heap] In abstract classes, only retain abstract methods.… [`#6`](https://github.com/zrwusa/data-structure-typed/pull/6) +- [binary-tree, graph] In order to optimize the design of Binary + Trees,… [`#7`](https://github.com/zrwusa/data-structure-typed/pull/7) +- [BinaryTree, Heap] In abstract classes, only retain abstract + methods.… [`#6`](https://github.com/zrwusa/data-structure-typed/pull/6) - [heap] test [`#5`](https://github.com/zrwusa/data-structure-typed/pull/5) -- [heap, priority queue] Heap improved. References #123: redesigned [`#4`](https://github.com/zrwusa/data-structure-typed/pull/4) +- [heap, priority queue] Heap improved. References #123: + redesigned [`#4`](https://github.com/zrwusa/data-structure-typed/pull/4) - test [`#3`](https://github.com/zrwusa/data-structure-typed/pull/3) ## [v1.35.0](https://github.com/zrwusa/data-structure-typed/compare/v1.34.1...v1.35.0) (11 October 2023) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 9e2c9e9..ebb954e 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -2,7 +2,10 @@ ## Our Commitment -We, as members, contributors, and leaders, solemnly pledge to ensure that participation in our community is an experience free from harassment for everyone, regardless of their age, body size, visible or invisible disabilities, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. +We, as members, contributors, and leaders, solemnly pledge to ensure that participation in our community is an +experience free from harassment for everyone, regardless of their age, body size, visible or invisible disabilities, +ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity and orientation. We commit to engaging in behaviors that foster an open, welcoming, diverse, inclusive, and healthy community. @@ -26,55 +29,74 @@ Unacceptable behaviors include: ## Enforcement Responsibilities -Community leaders bear the responsibility of clarifying and enforcing our standards of acceptable behavior. They will take fair and appropriate corrective actions in response to any behavior they deem inappropriate, threatening, offensive, or harmful. +Community leaders bear the responsibility of clarifying and enforcing our standards of acceptable behavior. They will +take fair and appropriate corrective actions in response to any behavior they deem inappropriate, threatening, +offensive, or harmful. -Community leaders have the authority and duty to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that do not align with this Code of Conduct. They will communicate the reasons for moderation decisions when deemed necessary. +Community leaders have the authority and duty to remove, edit, or reject comments, commits, code, wiki edits, issues, +and other contributions that do not align with this Code of Conduct. They will communicate the reasons for moderation +decisions when deemed necessary. ## Scope -This Code of Conduct is applicable in all community spaces and extends to instances when an individual officially represents the community in public spaces. Examples of representing our community include using an official email address, posting through an official social media account, or acting as an appointed representative at an online or offline event. +This Code of Conduct is applicable in all community spaces and extends to instances when an individual officially +represents the community in public spaces. Examples of representing our community include using an official email +address, posting through an official social media account, or acting as an appointed representative at an online or +offline event. ## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at zrwusa@gmail.com. All complaints will be promptly and fairly reviewed and investigated. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible +for enforcement at zrwusa@gmail.com. All complaints will be promptly and fairly reviewed and investigated. All community leaders are obligated to uphold the privacy and security of the reporter of any incident. ## Enforcement Guidelines -Community leaders will adhere to these Community Impact Guidelines when determining consequences for actions that violate this Code of Conduct: +Community leaders will adhere to these Community Impact Guidelines when determining consequences for actions that +violate this Code of Conduct: ### Correction Community Impact: The use of inappropriate language or other unprofessional or unwelcome behavior within the community. -Consequence: A private, written warning from community leaders, providing clarity regarding the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. +Consequence: A private, written warning from community leaders, providing clarity regarding the nature of the violation +and an explanation of why the behavior was inappropriate. A public apology may be requested. ### Warning Community Impact: A violation through a single incident or a series of actions. -Consequence: A warning with consequences for continued behavior. No interaction with the individuals involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed for a specified period of time. This includes refraining from interactions in community spaces as well as external channels like social media. Violating these terms may result in a temporary or permanent ban. +Consequence: A warning with consequences for continued behavior. No interaction with the individuals involved, including +unsolicited interaction with those enforcing the Code of Conduct, is allowed for a specified period of time. This +includes refraining from interactions in community spaces as well as external channels like social media. Violating +these terms may result in a temporary or permanent ban. ### Temporary Ban Community Impact: A serious violation of community standards, including sustained inappropriate behavior. -Consequence: A temporary ban from any form of interaction or public communication with the community for a specified period. No public or private interaction with the individuals involved, including unsolicited interaction with those enforcing the Code of Conduct, is permitted during this time. Violating these terms may lead to a permanent ban. +Consequence: A temporary ban from any form of interaction or public communication with the community for a specified +period. No public or private interaction with the individuals involved, including unsolicited interaction with those +enforcing the Code of Conduct, is permitted during this time. Violating these terms may lead to a permanent ban. ### Permanent Ban -Community Impact: Demonstrating a pattern of violating community standards, including sustained inappropriate behavior, harassment of an individual, or aggression towards or disparagement of classes of individuals. +Community Impact: Demonstrating a pattern of violating community standards, including sustained inappropriate behavior, +harassment of an individual, or aggression towards or disparagement of classes of individuals. Consequence: A permanent ban from any form of public interaction within the community. [//]: # (## Attribution) [//]: # () + [//]: # (The Community Impact Guidelines drew inspiration from Mozilla's code of conduct enforcement ladder.) [//]: # () + [//]: # (For answers to common questions about this code of conduct, please refer to the FAQ at https://www.zrwusa.org/faq.) [//]: # () + [//]: # (Translations are available at https://www.zrwusa.org/translations.) diff --git a/COMMANDS.md b/COMMANDS.md index 9a745a4..aa3c6e5 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -4,7 +4,8 @@ Overview of the commands to test, run and build this project as well as those th ## Most important commands for development -- `npm install` Installs all dependencies and creates the folder `node_modules`, that is needed for all following commands. +- `npm install` Installs all dependencies and creates the folder `node_modules`, that is needed for all following + commands. - `npm run lint` Lint src/ and test/ codebase (using ESLint) - `npm run format` Pretty src/ and test/ codebase (using Prettier) - `npm run inspect` Check src/ and test/ codebase (using TSC and ESLint) @@ -18,6 +19,7 @@ Overview of the commands to test, run and build this project as well as those th - `npm run test:perf -- priority-queue.test` Run specific performance test [//]: # (- `npm run coverage-badge` Updates code coverage badge inside `README.md`) + - `npm run build:docs` Generates JSDoc Documentation in folder "docs" - `npm run build` Build the application for production including es6(ESModule), es5(CommonJS) and minification(UMD) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index db53243..59f216c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,9 +68,10 @@ **Contributing new features** -- To ensure that there are no conflicts when merging the branch into the main branch, -- it is necessary to perform the following steps each time new development is going to be conducted on non-main branches: -- `git pull`, +- To ensure that there are no conflicts when merging the branch into the main branch, +- it is necessary to perform the following steps each time new development is going to be conducted on non-main + branches: +- `git pull`, - `git rebase main` - resolve conflicts before continuing the development. - After new features developed diff --git a/README.md b/README.md index 307615f..deae4ba 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,12 @@ Data Structures of Javascript & TypeScript. -Do you envy C++ with [STL]() (std::), Python with [collections](), and Java with [java.util]() ? Well, no need to envy anymore! JavaScript and TypeScript now have [data-structure-typed](). +Do you envy C++ with [STL]() (std::), Python with [collections](), and Java with [java.util]() ? Well, no need to envy +anymore! JavaScript and TypeScript now have [data-structure-typed](). Now you can use this in Node.js and browser environments -CommonJS:**`require export.modules =`** +CommonJS:**`require export.modules =`** ESModule:   **`import export`** @@ -59,16 +60,19 @@ import { Copy the line below into the head tag in an HTML document. #### development + ```html ``` #### production + ```html ``` Copy the code below into the script tag of your HTML, and you're good to go with your development. + ```js const {Heap} = dataStructureTyped; const { @@ -81,45 +85,44 @@ const { ## Vivid Examples ### Binary Tree -[Try it out](https://vivid-algorithm.vercel.app/), or you can run your own code using our [visual tool](https://github.com/zrwusa/vivid-algorithm) + +[Try it out](https://vivid-algorithm.vercel.app/), or you can run your own code using +our [visual tool](https://github.com/zrwusa/vivid-algorithm) ![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/binary-tree-array-to-binary-tree.webp) - - ### Binary Tree DFS + [Try it out](https://vivid-algorithm.vercel.app/) ![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/binary-tree-dfs-in-order.webp) - - ### AVL Tree + [Try it out](https://vivid-algorithm.vercel.app/) ![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/avl-tree-test.webp) - ### Tree Multi Map + [Try it out](https://vivid-algorithm.vercel.app/) ![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/tree-multiset-test.webp) - - ### Matrix + [Try it out](https://vivid-algorithm.vercel.app/algorithm/graph/) ![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/matrix-cut-off-tree-for-golf.webp) - ### Directed Graph + [Try it out](https://vivid-algorithm.vercel.app/algorithm/graph/) ![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/directed-graph-test.webp) - ### Map Graph + [Try it out](https://vivid-algorithm.vercel.app/algorithm/graph/) ![](https://raw.githubusercontent.com/zrwusa/assets/master/images/data-structure-typed/examples/videos/webp_output/map-graph-test.webp) @@ -778,6 +781,7 @@ Array.from(dijkstraResult?.seen ?? []).map(vertex => vertex.key) // ['A', 'B', ' ## Software Engineering Design Standards + diff --git a/SECURITY.md b/SECURITY.md index f17e3ab..7459cea 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -3,7 +3,7 @@ ## Supported Versions | Version | Supported | -|---------| ------------------ | +|---------|--------------------| | 1.30.x | :white_check_mark: | | < 3.0 | :x: | diff --git a/jest.config.js b/jest.config.js index 4c2e449..f4e1ecd 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,7 +3,7 @@ module.exports = { testEnvironment: 'node', testMatch: ['/test/unit/**/*.test.ts', '/test/unit/**/*.test.js'], collectCoverage: true, - coverageReporters: ['clover', 'json', 'lcov', ['text', {skipFull: true}], "json-summary"], + coverageReporters: ['clover', 'json', 'lcov', ['text', { skipFull: true }], "json-summary"], coverageDirectory: 'coverage', collectCoverageFrom: [ 'src/data-structures/**/*.{ts,js}', diff --git a/src/data-structures/binary-tree/avl-tree.ts b/src/data-structures/binary-tree/avl-tree.ts index cacd812..b37d2e5 100644 --- a/src/data-structures/binary-tree/avl-tree.ts +++ b/src/data-structures/binary-tree/avl-tree.ts @@ -39,7 +39,7 @@ export class AVLTree = AVLTreeNode>, options?: Partial) { super([], options); - if (elements) this.addMany(elements); + if (elements) super.addMany(elements); } /** diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts index 7e16d98..8accae8 100644 --- a/src/data-structures/binary-tree/binary-tree.ts +++ b/src/data-structures/binary-tree/binary-tree.ts @@ -268,18 +268,11 @@ export class BinaryTree = BinaryTreeNode */ addMany(nodes: Iterable>): (N | null | undefined)[] { // TODO not sure addMany not be run multi times - const keysOrNodes = [...nodes]; - return keysOrNodes.map((keyOrNode, i) => { - if (keyOrNode instanceof BinaryTreeNode) { - return this.add(keyOrNode); - } - - if (keyOrNode === null) { - return this.add(null); - } - - return this.add(keyOrNode); - }); + const inserted: (N | null | undefined)[] = []; + for (const kne of nodes) { + inserted.push(this.add(kne)); + } + return inserted; } /** diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts index 0599afb..d0fbf47 100644 --- a/src/data-structures/binary-tree/bst.ts +++ b/src/data-structures/binary-tree/bst.ts @@ -237,7 +237,6 @@ export class BST = BSTNode> } const realBTNExemplars: BTNodePureExemplar[] = []; - const isRealBTNExemplar = (kve: BTNodeExemplar): kve is BTNodePureExemplar => { if (kve === undefined || kve === null) return false; return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null)); diff --git a/src/data-structures/binary-tree/rb-tree.ts b/src/data-structures/binary-tree/rb-tree.ts index dbebd42..95eae38 100644 --- a/src/data-structures/binary-tree/rb-tree.ts +++ b/src/data-structures/binary-tree/rb-tree.ts @@ -56,7 +56,7 @@ export class RedBlackTree = RedBlackTr super([], options); this._root = this.Sentinel; - if (elements) this.addMany(elements); + if (elements) super.addMany(elements); } protected _root: N; diff --git a/test/integration/all-in-one.ts b/test/integration/all-in-one.test.ts similarity index 98% rename from test/integration/all-in-one.ts rename to test/integration/all-in-one.test.ts index ee053b0..34f8443 100644 --- a/test/integration/all-in-one.ts +++ b/test/integration/all-in-one.test.ts @@ -5,7 +5,7 @@ describe('AVL Tree Test from data-structure-typed', () => { const keys = [11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]; const tree = new AVLTree(); - for (const i of keys) tree.add(i, i); + for (const i of keys) tree.add([i, i]); const node6 = tree.get(6); diff --git a/tsconfig-cjs.json b/tsconfig-cjs.json index c13497c..d4132ab 100644 --- a/tsconfig-cjs.json +++ b/tsconfig-cjs.json @@ -6,7 +6,7 @@ "module": "CommonJS", "target": "ES2015", "moduleResolution": "node", - "sourceMap": true, + "sourceMap": true }, "include": [ "./src/**/*.ts"
Principle