refactor: Explicitly call the super.addMany method. chore: reformat project configs

This commit is contained in:
Revone 2023-11-25 20:59:34 +08:00
parent b099b759e8
commit 76db084bda
18 changed files with 108 additions and 74 deletions

View file

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

View file

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

View file

@ -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.

View file

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

View file

@ -2,7 +2,7 @@ name: data-structure-typed
on:
release:
types: [created]
types: [ created ]
jobs:
build:

View file

@ -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)

View file

@ -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.)

View file

@ -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)

View file

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

View file

@ -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
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.js'></script>
```
#### production
```html
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/data-structure-typed.min.js'></script>
```
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', '
</table>
## Software Engineering Design Standards
<table>
<tr>
<th>Principle</th>

View file

@ -3,7 +3,7 @@
## Supported Versions
| Version | Supported |
|---------| ------------------ |
|---------|--------------------|
| 1.30.x | :white_check_mark: |
| < 3.0 | :x: |

View file

@ -3,7 +3,7 @@ module.exports = {
testEnvironment: 'node',
testMatch: ['<rootDir>/test/unit/**/*.test.ts', '<rootDir>/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}',

View file

@ -39,7 +39,7 @@ export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode<V, AVLTr
*/
constructor(elements?: Iterable<BTNodeExemplar<V, N>>, options?: Partial<AVLTreeOptions>) {
super([], options);
if (elements) this.addMany(elements);
if (elements) super.addMany(elements);
}
/**

View file

@ -268,18 +268,11 @@ export class BinaryTree<V = any, N extends BinaryTreeNode<V, N> = BinaryTreeNode
*/
addMany(nodes: Iterable<BTNodeExemplar<V, N>>): (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;
}
/**

View file

@ -237,7 +237,6 @@ export class BST<V = any, N extends BSTNode<V, N> = BSTNode<V, BSTNodeNested<V>>
}
const realBTNExemplars: BTNodePureExemplar<V, N>[] = [];
const isRealBTNExemplar = (kve: BTNodeExemplar<V, N>): kve is BTNodePureExemplar<V, N> => {
if (kve === undefined || kve === null) return false;
return !(this.isEntry(kve) && (kve[0] === undefined || kve[0] === null));

View file

@ -56,7 +56,7 @@ export class RedBlackTree<V = any, N extends RedBlackTreeNode<V, N> = RedBlackTr
super([], options);
this._root = this.Sentinel;
if (elements) this.addMany(elements);
if (elements) super.addMany(elements);
}
protected _root: N;

View file

@ -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);

View file

@ -6,7 +6,7 @@
"module": "CommonJS",
"target": "ES2015",
"moduleResolution": "node",
"sourceMap": true,
"sourceMap": true
},
"include": [
"./src/**/*.ts"