diff --git a/CHANGELOG.md b/CHANGELOG.md index eea0a8b..faa6716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.38.8](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) +## [v1.38.9](https://github.com/zrwusa/data-structure-typed/compare/v1.35.0...main) (upcoming) ### Changes diff --git a/README.md b/README.md index fe1284f..dc413a5 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ bst.getDepth(6) === 3; // true bst.getLeftMost()?.id === 1; // true -bst.remove(6); +bst.delete(6); bst.get(6); // null bst.isAVLBalanced(); // true bst.bfs()[0] === 11; // true @@ -121,7 +121,7 @@ objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8}, {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7}, {id: 10, keyA: 10}, {id: 5, keyA: 5}]); -objBST.remove(11); +objBST.delete(11); ``` #### JS @@ -142,7 +142,7 @@ bst.getDepth(6) === 3; // true const leftMost = bst.getLeftMost(); leftMost?.id === 1; // true expect(leftMost?.id).toBe(1); -bst.remove(6); +bst.delete(6); bst.get(6); // null bst.isAVLBalanced(); // true or false const bfsIDs = bst.bfs(); @@ -159,12 +159,12 @@ objBST.addMany([{id: 15, keyA: 15}, {id: 1, keyA: 1}, {id: 8, keyA: 8}, {id: 14, keyA: 14}, {id: 4, keyA: 4}, {id: 7, keyA: 7}, {id: 10, keyA: 10}, {id: 5, keyA: 5}]); -objBST.remove(11); +objBST.delete(11); const avlTree = new AVLTree(); avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]) avlTree.isAVLBalanced(); // true -avlTree.remove(10); +avlTree.delete(10); avlTree.isAVLBalanced(); // true ``` @@ -178,7 +178,7 @@ import {AVLTree} from 'data-structure-typed'; const avlTree = new AVLTree(); avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]) avlTree.isAVLBalanced(); // true -avlTree.remove(10); +avlTree.delete(10); avlTree.isAVLBalanced(); // true ``` @@ -190,7 +190,7 @@ const {AVLTree} = require('data-structure-typed'); const avlTree = new AVLTree(); avlTree.addMany([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]) avlTree.isAVLBalanced(); // true -avlTree.remove(10); +avlTree.delete(10); avlTree.isAVLBalanced(); // true ``` @@ -214,7 +214,7 @@ graph.addEdge('A', 'B'); graph.hasEdge('A', 'B'); // true graph.hasEdge('B', 'A'); // false -graph.removeEdgeSrcToDest('A', 'B'); +graph.deleteEdgeSrcToDest('A', 'B'); graph.hasEdge('A', 'B'); // false graph.addVertex('C'); @@ -237,7 +237,7 @@ graph.addVertex('A'); graph.addVertex('B'); graph.addVertex('C'); graph.addVertex('D'); -graph.removeVertex('C'); +graph.deleteVertex('C'); graph.addEdge('A', 'B'); graph.addEdge('B', 'D'); diff --git a/package-lock.json b/package-lock.json index 33961d3..fe7c2c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "data-structure-typed", - "version": "1.38.8", + "version": "1.38.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "data-structure-typed", - "version": "1.38.8", + "version": "1.38.9", "license": "MIT", "devDependencies": { "@types/benchmark": "^2.1.3", @@ -15,17 +15,17 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.38.7", + "avl-tree-typed": "^1.38.8", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.38.7", - "bst-typed": "^1.38.7", + "binary-tree-typed": "^1.38.8", + "bst-typed": "^1.38.8", "dependency-cruiser": "^14.1.0", "eslint": "^8.50.0", "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-alias": "^1.1.2", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", - "heap-typed": "^1.38.7", + "heap-typed": "^1.38.8", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "prettier": "^3.0.3", @@ -2728,12 +2728,12 @@ } }, "node_modules/avl-tree-typed": { - "version": "1.38.7", - "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.38.7.tgz", - "integrity": "sha512-B5lOJoYI/8Y+WUI+atnN8FtKwjOZk6X91O55Qu8p6nauduOZlJvx0HtN3mmTKk0bYNqEHDNK5iyHD60Rwqx5Hw==", + "version": "1.38.8", + "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.38.8.tgz", + "integrity": "sha512-TMR5vZgH2fGUWDHqG7LNnGmWximwzg4tGthKNT3l9bL7zGnAg2C406j/6Hp/J29mvb5DV+j2NCCeBXmhu/B+AA==", "dev": true, "dependencies": { - "data-structure-typed": "^1.38.7" + "data-structure-typed": "^1.38.8" } }, "node_modules/babel-jest": { @@ -2927,12 +2927,12 @@ } }, "node_modules/binary-tree-typed": { - "version": "1.38.7", - "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.38.7.tgz", - "integrity": "sha512-Z/xh9iEg0r7WNUzRAPa/yPHJJpc3s0jgC8bioiKgoIU67wxV8Mbn5WbuF+m2oXXpYyaM4qhC+AGU43OkHss7rQ==", + "version": "1.38.8", + "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.38.8.tgz", + "integrity": "sha512-sS1Efx5XDFY8d1r+pLrt17sZH2bDQbhzJm27OFPO6p/Qkz7qSeJZhYTrpnbr2IFjk3eh0ljkIa3e9+s7AYfhow==", "dev": true, "dependencies": { - "data-structure-typed": "^1.38.7" + "data-structure-typed": "^1.38.8" } }, "node_modules/brace-expansion": { @@ -3011,12 +3011,12 @@ } }, "node_modules/bst-typed": { - "version": "1.38.7", - "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.38.7.tgz", - "integrity": "sha512-jo8owKRnKPOAbdqR6SmvWjF2yceqN/3j736xujDum4Uh8devBLguV7m49HUv7pfkKAx8uwuuE+6b0dPQaxR4vA==", + "version": "1.38.8", + "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.38.8.tgz", + "integrity": "sha512-gv3w5u3YIpnmQltcxWbLtpFqom3/z9b/NPdtc57m6rPaRAAWQy4pzyXAETgQX29p8RrCkVn/2cZLC6i6YfEjWw==", "dev": true, "dependencies": { - "data-structure-typed": "^1.38.7" + "data-structure-typed": "^1.38.8" } }, "node_modules/buffer-from": { @@ -3413,9 +3413,9 @@ } }, "node_modules/data-structure-typed": { - "version": "1.38.7", - "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.38.7.tgz", - "integrity": "sha512-YPV3hlUFTAG93+LoW8eaMv+KS4s9PF5MfpvvUkZybuR7WxqLtamCXWE1o3TRKkYFa9MEguxcq5ZaniCdeLg8Mw==", + "version": "1.38.8", + "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.38.8.tgz", + "integrity": "sha512-HU+9+HqDLN9f9ipANtibwkK3d65f0FzpvuKavrHSbBMiJvufwchZUxNkfmwGLqgdX8MUGw/Rrk15GpEloYhKNw==", "dev": true }, "node_modules/debug": { @@ -4771,12 +4771,12 @@ } }, "node_modules/heap-typed": { - "version": "1.38.7", - "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.38.7.tgz", - "integrity": "sha512-9ASCFfeKkN8iPFqgRUskah+a3RAxG4f+sbTVE8xRv4xwHpPLfwGo7gbJLkiJ5fkV+0PRN/ZXUkQPT5cI0XcbZQ==", + "version": "1.38.8", + "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.38.8.tgz", + "integrity": "sha512-jckb42KnKLidVpfbAChCkrYKFU1rVvTXiH/2G6ABsipzhOIvpM5ItIiR20hT2QP6wkUsEg/CG/K7h3HDQIsXXg==", "dev": true, "dependencies": { - "data-structure-typed": "^1.38.7" + "data-structure-typed": "^1.38.8" } }, "node_modules/html-escaper": { diff --git a/package.json b/package.json index de686d2..af9208a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.38.8", + "version": "1.38.9", "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", @@ -61,17 +61,17 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.38.7", + "avl-tree-typed": "^1.38.8", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.38.7", - "bst-typed": "^1.38.7", + "binary-tree-typed": "^1.38.8", + "bst-typed": "^1.38.8", "dependency-cruiser": "^14.1.0", "eslint": "^8.50.0", "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-alias": "^1.1.2", "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", - "heap-typed": "^1.38.7", + "heap-typed": "^1.38.8", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "prettier": "^3.0.3", diff --git a/src/data-structures/graph/abstract-graph.ts b/src/data-structures/graph/abstract-graph.ts index f93a731..49ecc28 100644 --- a/src/data-structures/graph/abstract-graph.ts +++ b/src/data-structures/graph/abstract-graph.ts @@ -130,7 +130,7 @@ export abstract class AbstractGraph< */ abstract createEdge(srcOrV1: VertexKey | string, destOrV2: VertexKey | string, weight?: number, val?: E): E; - abstract removeEdge(edge: E): E | null; + abstract deleteEdge(edge: E): E | null; abstract getEdge(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null; @@ -179,12 +179,12 @@ export abstract class AbstractGraph< } /** - * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself. + * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself. * @param {V | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`V`) or a vertex ID * (`VertexKey`). * @returns The method is returning a boolean value. */ - removeVertex(vertexOrKey: V | VertexKey): boolean { + deleteVertex(vertexOrKey: V | VertexKey): boolean { const vertexKey = this._getVertexKey(vertexOrKey); return this._vertices.delete(vertexKey); } @@ -199,7 +199,7 @@ export abstract class AbstractGraph< removeAllVertices(vertices: V[] | VertexKey[]): boolean { const removed: boolean[] = []; for (const v of vertices) { - removed.push(this.removeVertex(v)); + removed.push(this.deleteVertex(v)); } return removed.length > 0; } diff --git a/src/data-structures/graph/directed-graph.ts b/src/data-structures/graph/directed-graph.ts index f30a841..cc29bf3 100644 --- a/src/data-structures/graph/directed-graph.ts +++ b/src/data-structures/graph/directed-graph.ts @@ -153,7 +153,7 @@ export class DirectedGraph = DirectedVertex, E ext * @param {V | VertexKey} destOrKey - The `destOrKey` parameter represents the destination vertex or its ID. * @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist. */ - removeEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null { + deleteEdgeSrcToDest(srcOrKey: V | VertexKey, destOrKey: V | VertexKey): E | null { const src: V | null = this._getVertex(srcOrKey); const dest: V | null = this._getVertex(destOrKey); let removed: E | null = null; @@ -177,9 +177,9 @@ export class DirectedGraph = DirectedVertex, E ext * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found. * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src` * and `dest`, which represent the source and destination vertices of the edge, respectively. - * @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist. + * @returns The method `deleteEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist. */ - removeEdge(edge: E): E | null { + deleteEdge(edge: E): E | null { let removed: E | null = null; const src = this._getVertex(edge.src); const dest = this._getVertex(edge.dest); @@ -206,12 +206,12 @@ export class DirectedGraph = DirectedVertex, E ext * the second vertex in the edge that needs to be removed. * @returns an array of removed edges (E[]). */ - removeEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[] { + deleteEdgesBetween(v1: VertexKey | V, v2: VertexKey | V): E[] { const removed: E[] = []; if (v1 && v2) { - const v1ToV2 = this.removeEdgeSrcToDest(v1, v2); - const v2ToV1 = this.removeEdgeSrcToDest(v2, v1); + const v1ToV2 = this.deleteEdgeSrcToDest(v1, v2); + const v2ToV1 = this.deleteEdgeSrcToDest(v2, v1); v1ToV2 && removed.push(v1ToV2); v2ToV1 && removed.push(v2ToV1); diff --git a/src/data-structures/graph/undirected-graph.ts b/src/data-structures/graph/undirected-graph.ts index a7a81ff..8bdf1c2 100644 --- a/src/data-structures/graph/undirected-graph.ts +++ b/src/data-structures/graph/undirected-graph.ts @@ -127,7 +127,7 @@ export class UndirectedGraph< * (VertexKey). It represents the second vertex of the edge that needs to be removed. * @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist. */ - removeEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null { + deleteEdgeBetween(v1: V | VertexKey, v2: V | VertexKey): E | null { const vertex1: V | null = this._getVertex(v1); const vertex2: V | null = this._getVertex(v2); @@ -148,12 +148,12 @@ export class UndirectedGraph< } /** - * The removeEdge function removes an edge between two vertices in a graph. + * The deleteEdge function removes an edge between two vertices in a graph. * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph. * @returns The method is returning either the removed edge (of type E) or null if the edge was not found. */ - removeEdge(edge: E): E | null { - return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]); + deleteEdge(edge: E): E | null { + return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]); } /** diff --git a/test/unit/data-structures/graph/directed-graph.test.ts b/test/unit/data-structures/graph/directed-graph.test.ts index e942041..fcd8443 100644 --- a/test/unit/data-structures/graph/directed-graph.test.ts +++ b/test/unit/data-structures/graph/directed-graph.test.ts @@ -40,7 +40,7 @@ describe('DirectedGraph Operation Test', () => { graph.addVertex(vertex2); graph.addEdge(edge); - expect(graph.removeEdge(edge)).toBe(edge); + expect(graph.deleteEdge(edge)).toBe(edge); expect(graph.hasEdge('A', 'B')).toBe(false); }); @@ -164,7 +164,7 @@ describe('Inherit from DirectedGraph and perform operations', () => { myGraph.addVertex(2, 'data2'); myGraph.addEdge(1, 2, 10, 'edge-data1-2'); - const removedEdge = myGraph.removeEdgeSrcToDest(1, 2); + const removedEdge = myGraph.deleteEdgeSrcToDest(1, 2); const edgeAfterRemoval = myGraph.getEdge(1, 2); expect(removedEdge).toBeInstanceOf(MyEdge); @@ -233,7 +233,7 @@ describe('Inherit from DirectedGraph and perform operations test2.', () => { expect(myGraph.getEdge(2, 1)).toBeTruthy(); expect(myGraph.getEdge(1, '100')).toBeFalsy(); - myGraph.removeEdgeSrcToDest(1, 2); + myGraph.deleteEdgeSrcToDest(1, 2); expect(myGraph.getEdge(1, 2)).toBeFalsy(); myGraph.addEdge(3, 1, 3, 'edge-data-3-1'); diff --git a/test/unit/data-structures/graph/overall.test.ts b/test/unit/data-structures/graph/overall.test.ts index 883ff5d..fee3094 100644 --- a/test/unit/data-structures/graph/overall.test.ts +++ b/test/unit/data-structures/graph/overall.test.ts @@ -20,7 +20,7 @@ describe('Overall Graph Operation Test', () => { expect(graph.hasEdge('A', 'B')).toBe(true); // true expect(graph.hasEdge('B', 'A')).toBe(false); // false - graph.removeEdgeSrcToDest('A', 'B'); + graph.deleteEdgeSrcToDest('A', 'B'); graph.hasEdge('A', 'B'); // false expect(graph.hasEdge('A', 'B')).toBe(false); // false @@ -38,7 +38,7 @@ describe('Overall Graph Operation Test', () => { graph.addVertex('B'); graph.addVertex('C'); graph.addVertex('D'); - graph.removeVertex('C'); + graph.deleteVertex('C'); graph.addEdge('A', 'B'); graph.addEdge('B', 'D'); diff --git a/test/unit/data-structures/graph/undirected-graph.test.ts b/test/unit/data-structures/graph/undirected-graph.test.ts index 3d0eb6e..9d81ee1 100644 --- a/test/unit/data-structures/graph/undirected-graph.test.ts +++ b/test/unit/data-structures/graph/undirected-graph.test.ts @@ -40,7 +40,7 @@ describe('UndirectedGraph Operation Test', () => { graph.addVertex(vertex2); graph.addEdge(edge); - expect(graph.removeEdge(edge)).toBe(edge); + expect(graph.deleteEdge(edge)).toBe(edge); expect(graph.hasEdge('A', 'B')).toBe(false); }); @@ -49,7 +49,7 @@ describe('UndirectedGraph Operation Test', () => { graph.addVertex('B'); graph.addVertex('C'); graph.addVertex('D'); - graph.removeVertex('C'); + graph.deleteVertex('C'); graph.addEdge('A', 'B'); graph.addEdge('B', 'D');