[optimization] allow all list datatype delete methods to accept null as an input argument

This commit is contained in:
Revone 2023-10-26 16:45:08 +08:00
parent 2d518151ae
commit 31c228668e
9 changed files with 29 additions and 37 deletions

View file

@ -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.37.3](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
## [v1.38.4](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming)
### Changes

View file

@ -56,7 +56,7 @@ import {
```html
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/umd/bundle.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/index.global.js'></script>
```
```js

28
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "data-structure-typed",
"version": "1.38.2",
"version": "1.38.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "data-structure-typed",
"version": "1.38.2",
"version": "1.38.4",
"license": "MIT",
"devDependencies": {
"@types/benchmark": "^2.1.3",
@ -15,10 +15,10 @@
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"auto-changelog": "^2.4.0",
"avl-tree-typed": "^1.38.2",
"avl-tree-typed": "^1.38.3",
"benchmark": "^2.1.4",
"binary-tree-typed": "^1.38.2",
"bst-typed": "^1.38.2",
"binary-tree-typed": "^1.38.3",
"bst-typed": "^1.38.3",
"dependency-cruiser": "^14.1.0",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",
@ -2728,9 +2728,9 @@
}
},
"node_modules/avl-tree-typed": {
"version": "1.38.2",
"resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.38.2.tgz",
"integrity": "sha512-2P1DPzdnTuvENa6bGA7vqglC+Ae8GndRSX4H5JeB4V5ZVoiWFpSDL2lO4kRJJYbceL+hemx4Ge/MriGYKgXIfQ==",
"version": "1.38.3",
"resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.38.3.tgz",
"integrity": "sha512-ecoSXprvLtWQlq3Cgp4HNeSeWQgruHyjePxZ8+2ldeUhNN0xgI4Bm8yv/GbN7wV6WGG3V85EidBnu9skZ7jDUA==",
"dev": true
},
"node_modules/babel-jest": {
@ -2924,9 +2924,9 @@
}
},
"node_modules/binary-tree-typed": {
"version": "1.38.2",
"resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.38.2.tgz",
"integrity": "sha512-odemWypyURZVq3qdegpaQDFydmt3sZA3uLHbcav3bBbnPj9WuMSIbOeOs21Nrj/yJHk1GrmlFRbPjYrrDXfdaw==",
"version": "1.38.3",
"resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.38.3.tgz",
"integrity": "sha512-fMnVgcByTNPM3D5sGJOQJ7/N3BUPqiMju4uTb7vDuGFC/sOcM1yN2MzbCEg/Ewwz7AQ7fydC2icuvqyY/AEUWA==",
"dev": true
},
"node_modules/brace-expansion": {
@ -3005,9 +3005,9 @@
}
},
"node_modules/bst-typed": {
"version": "1.38.2",
"resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.38.2.tgz",
"integrity": "sha512-BcTSvIbi8m5kEqzlS++YYlg2IgKhuqsX1mu200BLGq4d327vsQq9hY8TneuL54N4KAr4McR2GqpkDaHXQ3eTbw==",
"version": "1.38.3",
"resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.38.3.tgz",
"integrity": "sha512-T83xkJXfuTjh0wGLiabSqmje4Ky5VxAfYA0RcM4UcgM7lFsYvyGwuSaI9AEWYbr+8Tb2sKqQ8uNP45mF+rB9Lg==",
"dev": true
},
"node_modules/buffer-from": {

View file

@ -1,6 +1,6 @@
{
"name": "data-structure-typed",
"version": "1.38.3",
"version": "1.38.4",
"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/cjs/index.js",
"module": "dist/mjs/index.js",
@ -39,7 +39,7 @@
"copy:to-subs": "sh scripts/copy_to_all_subs.sh",
"publish:subs": "npm run copy:to-subs && sh scripts/publish_all_subs.sh",
"publish:docs": "sh scripts/publish_docs.sh",
"publish:all": "npm run ci && npm publish && npm run publish:subs && npm run publish:docs"
"publish:all": "npm run ci && npm publish && npm run publish:docs && npm run publish:subs"
},
"repository": {
"type": "git",
@ -61,10 +61,10 @@
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"auto-changelog": "^2.4.0",
"avl-tree-typed": "^1.38.2",
"avl-tree-typed": "^1.38.3",
"benchmark": "^2.1.4",
"binary-tree-typed": "^1.38.2",
"bst-typed": "^1.38.2",
"binary-tree-typed": "^1.38.3",
"bst-typed": "^1.38.3",
"dependency-cruiser": "^14.1.0",
"eslint": "^8.50.0",
"eslint-config-prettier": "^9.0.0",

View file

@ -61,8 +61,8 @@ for dir in "${directories[@]}"; do
# jq ".dependencies[\"data-structure-typed\"] = \"$version_prompted\"" package.json > temp.json
# mv temp.json package.json
# # Install data-structure-typed package and build
# npm i data-structure-typed@"$version_prompted"
# Install data-structure-typed package and build
npm i data-structure-typed@"$version_prompted"
npm run build:publish
cd ..

View file

@ -266,7 +266,7 @@ export class DoublyLinkedList<E = any> {
* @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
* is found in the linked list. If no such node is found, it returns `null`.
*/
findNode(val: E): DoublyLinkedListNode<E> | null {
findNode(val: E | null): DoublyLinkedListNode<E> | null {
let current = this.head;
while (current) {
@ -341,7 +341,7 @@ export class DoublyLinkedList<E = any> {
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
* deleted from the doubly linked list, and `false` if the value or node was not found in the list.
*/
delete(valOrNode: E | DoublyLinkedListNode<E>): boolean {
delete(valOrNode: E | DoublyLinkedListNode<E> | null): boolean {
let node: DoublyLinkedListNode<E> | null;
if (valOrNode instanceof DoublyLinkedListNode) {
@ -594,8 +594,6 @@ export class DoublyLinkedList<E = any> {
return false;
}
insertBefore(existingValueOrNode: E, newValue: E): boolean;
insertBefore(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
/**
* The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.

View file

@ -214,9 +214,6 @@ export class SinglyLinkedList<E = any> {
return removedNode!.val;
}
delete(valueOrNode: E): boolean;
delete(valueOrNode: SinglyLinkedListNode<E>): boolean;
/**
* The delete function removes a node with a specific value from a singly linked list.
* @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
@ -224,7 +221,8 @@ export class SinglyLinkedList<E = any> {
* @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
* successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
*/
delete(valueOrNode: E | SinglyLinkedListNode<E>): boolean {
delete(valueOrNode: E | SinglyLinkedListNode<E> | null | undefined): boolean {
if (!valueOrNode) return false;
let value: E;
if (valueOrNode instanceof SinglyLinkedListNode) {
value = valueOrNode.val;
@ -397,9 +395,6 @@ export class SinglyLinkedList<E = any> {
return null;
}
insertBefore(existingValue: E, newValue: E): boolean;
insertBefore(existingValue: SinglyLinkedListNode<E>, newValue: E): boolean;
/**
* The `insertBefore` function inserts a new value before an existing value in a singly linked list.
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the

View file

@ -1,5 +1,4 @@
import {BinaryTreeNode} from '../../../data-structures';
import PropertyKeysOf = jest.PropertyKeysOf;
/**
* Enum representing different loop types.

View file

@ -3,7 +3,7 @@
<head>
<meta charset='UTF-8'>
<title>CDN Test</title>
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/umd/bundle.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/data-structure-typed/dist/umd/index.global.js'></script>
</head>
<body>
<div id='app'>
@ -23,7 +23,7 @@
$avlTreeSpan.innerText = 'AVLTree';
$avlTree.append($avlTreeSpan);
avlTree.add(1, 1);
console.log(avlTree.BFS());
console.log(avlTree.bfs());
$modules.append($avlTree);