From ca7e60e465dd784db46cb289fbee557512bbea32 Mon Sep 17 00:00:00 2001 From: Revone Date: Fri, 22 Nov 2024 22:55:43 +1300 Subject: [PATCH] fix: rename the keyValueNodeEntryRawToNodeAndValue to _keyValueNodeEntryRawToNodeAndValue and make it protected --- CHANGELOG.md | 2 +- package-lock.json | 52 ++++++------ package.json | 10 +-- .../binary-tree/avl-tree-multi-map.ts | 4 +- .../binary-tree/binary-tree.ts | 4 +- src/data-structures/binary-tree/bst.ts | 6 +- src/data-structures/binary-tree/rb-tree.ts | 2 +- .../binary-tree/tree-multi-map.ts | 4 +- .../linked-list/doubly-linked-list.ts | 10 +++ src/data-structures/trie/trie.ts | 14 +--- .../binary-tree/binary-tree.test.ts | 70 ++++++++-------- .../data-structures/binary-tree/bst.test.ts | 80 +++++++++---------- 12 files changed, 131 insertions(+), 127 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d6dfb9..ab45579 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.53.6](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming) +## [v1.53.7](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming) ### Changes diff --git a/package-lock.json b/package-lock.json index 319f1dd..2d3376f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "data-structure-typed", - "version": "1.53.6", + "version": "1.53.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "data-structure-typed", - "version": "1.53.6", + "version": "1.53.7", "license": "MIT", "devDependencies": { "@eslint/compat": "^1.2.2", @@ -19,11 +19,11 @@ "@typescript-eslint/eslint-plugin": "^8.12.1", "@typescript-eslint/parser": "^8.12.1", "auto-changelog": "^2.5.0", - "avl-tree-typed": "^1.53.5", + "avl-tree-typed": "^1.53.6", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.53.5", - "bst-typed": "^1.53.5", - "data-structure-typed": "^1.53.5", + "binary-tree-typed": "^1.53.6", + "bst-typed": "^1.53.6", + "data-structure-typed": "^1.53.6", "dependency-cruiser": "^16.5.0", "doctoc": "^2.2.1", "eslint": "^9.13.0", @@ -32,7 +32,7 @@ "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import": "^2.31.0", "fast-glob": "^3.3.2", - "heap-typed": "^1.53.5", + "heap-typed": "^1.53.6", "istanbul-badges-readme": "^1.9.0", "jest": "^29.7.0", "js-sdsl": "^4.4.2", @@ -3437,13 +3437,13 @@ } }, "node_modules/avl-tree-typed": { - "version": "1.53.5", - "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.53.5.tgz", - "integrity": "sha512-BkJgD5S4ALEl4ytKKVvqz3Qo/19U2bxnOUyZxy3dMgXNh20vaPZAJ82bFRX2lAoBFBDmIgtWp/klxC0CrDO6nQ==", + "version": "1.53.6", + "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.53.6.tgz", + "integrity": "sha512-BmWYQG+mvfoS9yPVAm3CRL3omYdCO1Rohe7BGkYjvC1WHhd0A6FIrwu5Ge9kyrPxxqQsZWK/D4YHDqTyWkX4+A==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.53.5" + "data-structure-typed": "^1.53.6" } }, "node_modules/babel-jest": { @@ -3602,13 +3602,13 @@ } }, "node_modules/binary-tree-typed": { - "version": "1.53.5", - "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.53.5.tgz", - "integrity": "sha512-4DSrFAlykAMRF2w/hqaPG+vzsQLKq8TTnVBTD2c9Ew680+jHcanypDb6mzW0WJWSgA+v5V9IEX7P6Zz6/vS1rg==", + "version": "1.53.6", + "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.53.6.tgz", + "integrity": "sha512-cLjhoqLjoY+iMbMcvQsjT1jhCHkdGI4j3cEdLG4g3Vy99jipxiXQ3h9qSmWYo5HO7w5DBfU4v+xw4yI5lM3+AQ==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.53.5" + "data-structure-typed": "^1.53.6" } }, "node_modules/brace-expansion": { @@ -3691,13 +3691,13 @@ } }, "node_modules/bst-typed": { - "version": "1.53.5", - "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.53.5.tgz", - "integrity": "sha512-poYNwY4rwHinpNCQDsTv631XGUNJh/wvklLzaok+Nt+XV1PsH2e8VATaTCUMdTwLFrDn7jGFoY8mJkJjmr0s2w==", + "version": "1.53.6", + "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.53.6.tgz", + "integrity": "sha512-LKY9GMNdhYlb8Iprc8Z4143bQ6cWYhE8thSHb8jhvVzsEuqXqetM0tSG88a5QjURgxt+Mr9GGJruSeBYX7/vQw==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.53.5" + "data-structure-typed": "^1.53.6" } }, "node_modules/buffer-from": { @@ -4069,9 +4069,9 @@ } }, "node_modules/data-structure-typed": { - "version": "1.53.5", - "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.53.5.tgz", - "integrity": "sha512-v7gFtZe71/vS/+HR+eK3EZmljvp5ANJK3DiCjdLC5XGmzpLvJVwfYz+An9f8+FEoM6DXrKLAdDkZPU9m/hZW7g==", + "version": "1.53.6", + "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.53.6.tgz", + "integrity": "sha512-o3j49Yb5nPWyMIYvm6KOqlaj6SbUP/nq26kl6KmT0UknbOPfrElGIAdYwV9J87dHkHxGPGJG7Ee754jv8XjIIQ==", "dev": true, "license": "MIT" }, @@ -5946,13 +5946,13 @@ } }, "node_modules/heap-typed": { - "version": "1.53.5", - "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.53.5.tgz", - "integrity": "sha512-H5Vj0U+fXyvdyW5rSZ44kOI7WeThzaNihhwD7kQ+SkTjM9+sskUvx6JpZf62ca56NRt+57w42gg6A/A3S8W0bA==", + "version": "1.53.6", + "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.53.6.tgz", + "integrity": "sha512-MS8mjgg/rjV6wQmD/sqdr93M0WGezju/Q4KFULvF+JpD7XVmdpfN/w+h9fA4ZYkkI5Ih7JarJvvh8hHHWfpqIg==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.53.5" + "data-structure-typed": "^1.53.6" } }, "node_modules/html-escaper": { diff --git a/package.json b/package.json index 5486d08..8455bf6 100644 --- a/package.json +++ b/package.json @@ -70,11 +70,11 @@ "@typescript-eslint/eslint-plugin": "^8.12.1", "@typescript-eslint/parser": "^8.12.1", "auto-changelog": "^2.5.0", - "avl-tree-typed": "^1.53.5", + "avl-tree-typed": "^1.53.6", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.53.5", - "bst-typed": "^1.53.5", - "data-structure-typed": "^1.53.5", + "binary-tree-typed": "^1.53.6", + "bst-typed": "^1.53.6", + "data-structure-typed": "^1.53.6", "dependency-cruiser": "^16.5.0", "doctoc": "^2.2.1", "eslint": "^9.13.0", @@ -83,7 +83,7 @@ "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-import": "^2.31.0", "fast-glob": "^3.3.2", - "heap-typed": "^1.53.5", + "heap-typed": "^1.53.6", "istanbul-badges-readme": "^1.9.0", "jest": "^29.7.0", "js-sdsl": "^4.4.2", diff --git a/src/data-structures/binary-tree/avl-tree-multi-map.ts b/src/data-structures/binary-tree/avl-tree-multi-map.ts index 1d6af87..cc40171 100644 --- a/src/data-structures/binary-tree/avl-tree-multi-map.ts +++ b/src/data-structures/binary-tree/avl-tree-multi-map.ts @@ -173,7 +173,7 @@ export class AVLTreeMultiMap< * times the key-value pair should be added to the data structure. If not provided, it defaults to 1. * @returns either a NODE object or undefined. */ - override keyValueNodeEntryRawToNodeAndValue( + protected override _keyValueNodeEntryRawToNodeAndValue( keyNodeEntryOrRaw: BTNRep | R, value?: V, count = 1 @@ -217,7 +217,7 @@ export class AVLTreeMultiMap< * @returns a boolean value. */ override add(keyNodeEntryOrRaw: BTNRep | R, value?: V, count = 1): boolean { - const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count); + const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count); if (newNode === undefined) return false; const orgNodeCount = newNode?.count || 0; diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts index 2306c51..4a2566d 100644 --- a/src/data-structures/binary-tree/binary-tree.ts +++ b/src/data-structures/binary-tree/binary-tree.ts @@ -216,7 +216,7 @@ export class BinaryTree< * input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null * value. */ - keyValueNodeEntryRawToNodeAndValue( + protected _keyValueNodeEntryRawToNodeAndValue( keyNodeEntryOrRaw: BTNRep | R, value?: V ): [OptNodeOrNull, V | undefined] { @@ -420,7 +420,7 @@ export class BinaryTree< * key was found and the node was replaced instead of inserted. */ add(keyNodeEntryOrRaw: BTNRep | R, value?: V): boolean { - const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value); + const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value); if (newNode === undefined) return false; // If the tree is empty, directly set the new node as the root node diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts index 6ae50d7..813f153 100644 --- a/src/data-structures/binary-tree/bst.ts +++ b/src/data-structures/binary-tree/bst.ts @@ -233,11 +233,11 @@ export class BST< * value associated with a key in a key-value pair. * @returns either a NODE object or undefined. */ - override keyValueNodeEntryRawToNodeAndValue( + protected override _keyValueNodeEntryRawToNodeAndValue( keyNodeEntryOrRaw: BTNRep | R, value?: V ): [OptNode, V | undefined] { - const [node, entryValue] = super.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value); + const [node, entryValue] = super._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value); if (node === null) return [undefined, undefined]; return [node, value ?? entryValue]; } @@ -299,7 +299,7 @@ export class BST< * @returns a boolean value. */ override add(keyNodeEntryOrRaw: BTNRep | R, value?: V): boolean { - const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value); + const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value); if (newNode === undefined) return false; if (this._root === undefined) { diff --git a/src/data-structures/binary-tree/rb-tree.ts b/src/data-structures/binary-tree/rb-tree.ts index cf1bfaa..a081803 100644 --- a/src/data-structures/binary-tree/rb-tree.ts +++ b/src/data-structures/binary-tree/rb-tree.ts @@ -207,7 +207,7 @@ export class RedBlackTree< * returns true. If the node cannot be added or updated, the method returns false. */ override add(keyNodeEntryOrRaw: BTNRep | R, value?: V): boolean { - const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value); + const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value); if (!this.isRealNode(newNode)) return false; const insertStatus = this._insert(newNode); diff --git a/src/data-structures/binary-tree/tree-multi-map.ts b/src/data-structures/binary-tree/tree-multi-map.ts index ee38f54..1f41644 100644 --- a/src/data-structures/binary-tree/tree-multi-map.ts +++ b/src/data-structures/binary-tree/tree-multi-map.ts @@ -157,7 +157,7 @@ export class TreeMultiMap< * times the key-value pair should be added to the data structure. If not provided, it defaults to 1. * @returns either a NODE object or undefined. */ - override keyValueNodeEntryRawToNodeAndValue( + protected override _keyValueNodeEntryRawToNodeAndValue( keyNodeEntryOrRaw: BTNRep | R, value?: V, count = 1 @@ -212,7 +212,7 @@ export class TreeMultiMap< * was successful, and false otherwise. */ override add(keyNodeEntryOrRaw: BTNRep | R, value?: V, count = 1): boolean { - const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count); + const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count); const orgCount = newNode?.count || 0; const isSuccessAdded = super.add(newNode, newValue); diff --git a/src/data-structures/linked-list/doubly-linked-list.ts b/src/data-structures/linked-list/doubly-linked-list.ts index db616cc..93b2387 100644 --- a/src/data-structures/linked-list/doubly-linked-list.ts +++ b/src/data-structures/linked-list/doubly-linked-list.ts @@ -514,6 +514,16 @@ export class DoublyLinkedListNode { * console.log(scheduler.listProcesses()); // [] */ export class DoublyLinkedList extends IterableElementBase> { + /** + * This TypeScript constructor initializes a DoublyLinkedList with optional elements and options. + * @param {Iterable | Iterable} elements - The `elements` parameter in the constructor is an + * iterable collection of elements of type `E` or `R`. It is used to initialize the DoublyLinkedList + * with the elements provided in the iterable. If no elements are provided, the default value is an + * empty iterable. + * @param [options] - The `options` parameter in the constructor is of type + * `DoublyLinkedListOptions`. It is an optional parameter that allows you to pass additional + * configuration options to customize the behavior of the DoublyLinkedList. + */ constructor(elements: Iterable | Iterable = [], options?: DoublyLinkedListOptions) { super(options); this._head = undefined; diff --git a/src/data-structures/trie/trie.ts b/src/data-structures/trie/trie.ts index 5dd45d5..38b123b 100644 --- a/src/data-structures/trie/trie.ts +++ b/src/data-structures/trie/trie.ts @@ -94,17 +94,11 @@ export class TrieNode { * 11. Text Word Frequency Count: Counting and storing the frequency of words in a large amount of text data. * @example * // Autocomplete: Prefix validation and checking - * const autocomplete = new Trie([ - * 'gmail.com', - * 'gmail.co.nz', - * 'gmail.co.jp', - * 'yahoo.com', - * 'outlook.com' - * ]); + * const autocomplete = new Trie(['gmail.com', 'gmail.co.nz', 'gmail.co.jp', 'yahoo.com', 'outlook.com']); * * // Get all completions for a prefix * const gmailCompletions = autocomplete.getWords('gmail'); - * console.log(gmailCompletions); // ['gmail.com','gmail.co.nz','gmail.co.jp'] + * console.log(gmailCompletions); // ['gmail.com', 'gmail.co.nz', 'gmail.co.jp'] * @example * // File System Path Operations * const fileSystem = new Trie([ @@ -137,8 +131,8 @@ export class TrieNode { * ]); * * // Test autocomplete with different prefixes - * console.log(autocomplete.getWords('fun')); // ['functional', 'functions','function'] - * console.log(autocomplete.getWords('cla')); // ['classes', 'classical','class', ] + * console.log(autocomplete.getWords('fun')); // ['functional', 'functions', 'function'] + * console.log(autocomplete.getWords('cla')); // ['classes', 'classical', 'class'] * console.log(autocomplete.getWords('con')); // ['constructor', 'const'] * * // Test with non-matching prefix diff --git a/test/unit/data-structures/binary-tree/binary-tree.test.ts b/test/unit/data-structures/binary-tree/binary-tree.test.ts index b62eb6e..5881d08 100644 --- a/test/unit/data-structures/binary-tree/binary-tree.test.ts +++ b/test/unit/data-structures/binary-tree/binary-tree.test.ts @@ -733,41 +733,41 @@ describe('BinaryTree', () => { ]); }); - it('should keyValueNodeEntryRawToNodeAndValue', () => { - const tree = new BinaryTree(); - const node0 = tree.keyValueNodeEntryRawToNodeAndValue(0); - expect(node0).toEqual([ - { - _left: undefined, - _right: undefined, - key: 0, - parent: undefined, - value: undefined - }, - undefined - ]); - - const nodeUndefined = tree.keyValueNodeEntryRawToNodeAndValue(undefined); - expect(nodeUndefined).toEqual([undefined, undefined]); - - const nodeNull = tree.keyValueNodeEntryRawToNodeAndValue(null); - expect(nodeNull).toEqual([null, undefined]); - - const [, nodeWithSeparateValue] = tree.keyValueNodeEntryRawToNodeAndValue(7, 77); - expect(nodeWithSeparateValue).toBe(77); - - expect(tree.keyValueNodeEntryRawToNodeAndValue([undefined, 2])).toEqual([undefined, undefined]); - - expect(tree.keyValueNodeEntryRawToNodeAndValue(Symbol('test') as unknown as number)).toEqual([ - undefined, - undefined - ]); - - const bTree = new BinaryTree([], { - toEntryFn: (ele: { obj: { id: number } }) => [Symbol('test') as unknown as number, ele.obj.id] - }); - expect(bTree.keyValueNodeEntryRawToNodeAndValue({ obj: { id: 1 } })).toEqual([undefined, undefined]); - }); + // it('should keyValueNodeEntryRawToNodeAndValue', () => { + // const tree = new BinaryTree(); + // const node0 = tree.keyValueNodeEntryRawToNodeAndValue(0); + // expect(node0).toEqual([ + // { + // _left: undefined, + // _right: undefined, + // key: 0, + // parent: undefined, + // value: undefined + // }, + // undefined + // ]); + // + // const nodeUndefined = tree.keyValueNodeEntryRawToNodeAndValue(undefined); + // expect(nodeUndefined).toEqual([undefined, undefined]); + // + // const nodeNull = tree.keyValueNodeEntryRawToNodeAndValue(null); + // expect(nodeNull).toEqual([null, undefined]); + // + // const [, nodeWithSeparateValue] = tree.keyValueNodeEntryRawToNodeAndValue(7, 77); + // expect(nodeWithSeparateValue).toBe(77); + // + // expect(tree.keyValueNodeEntryRawToNodeAndValue([undefined, 2])).toEqual([undefined, undefined]); + // + // expect(tree.keyValueNodeEntryRawToNodeAndValue(Symbol('test') as unknown as number)).toEqual([ + // undefined, + // undefined + // ]); + // + // const bTree = new BinaryTree([], { + // toEntryFn: (ele: { obj: { id: number } }) => [Symbol('test') as unknown as number, ele.obj.id] + // }); + // expect(bTree.keyValueNodeEntryRawToNodeAndValue({ obj: { id: 1 } })).toEqual([undefined, undefined]); + // }); it('should replace value', () => { const tree = new BinaryTree([4, 5, [1, '1'], 2, 3], { isMapMode: false }); diff --git a/test/unit/data-structures/binary-tree/bst.test.ts b/test/unit/data-structures/binary-tree/bst.test.ts index 82ab088..8350be8 100644 --- a/test/unit/data-structures/binary-tree/bst.test.ts +++ b/test/unit/data-structures/binary-tree/bst.test.ts @@ -450,26 +450,26 @@ describe('BST operations test', () => { expect(bfsNodes[2].key).toBe(16); }); - it('should keyValueNodeEntryRawToNodeAndValue', () => { - const bst = new BST(); - const node0 = bst.keyValueNodeEntryRawToNodeAndValue(0); - expect(node0).toEqual([ - { - _left: undefined, - _right: undefined, - key: 0, - parent: undefined, - value: undefined - }, - undefined - ]); - - const nodeUndefined = bst.keyValueNodeEntryRawToNodeAndValue(undefined); - expect(nodeUndefined).toEqual([undefined, undefined]); - - const nodeNull = bst.keyValueNodeEntryRawToNodeAndValue(null); - expect(nodeNull).toEqual([undefined, undefined]); - }); + // it('should keyValueNodeEntryRawToNodeAndValue', () => { + // const bst = new BST(); + // const node0 = bst.keyValueNodeEntryRawToNodeAndValue(0); + // expect(node0).toEqual([ + // { + // _left: undefined, + // _right: undefined, + // key: 0, + // parent: undefined, + // value: undefined + // }, + // undefined + // ]); + // + // const nodeUndefined = bst.keyValueNodeEntryRawToNodeAndValue(undefined); + // expect(nodeUndefined).toEqual([undefined, undefined]); + // + // const nodeNull = bst.keyValueNodeEntryRawToNodeAndValue(null); + // expect(nodeNull).toEqual([undefined, undefined]); + // }); it('should replace value', () => { const tree = new BST([4, 5, [1, '1'], 2, 3], { isMapMode: false }); @@ -1340,26 +1340,26 @@ describe('BST operations not map mode test', () => { }); }); - it('should keyValueNodeEntryRawToNodeAndValue', () => { - const bst = new BST([], { isMapMode: false }); - const node0 = bst.keyValueNodeEntryRawToNodeAndValue(0); - expect(node0).toEqual([ - { - _left: undefined, - _right: undefined, - key: 0, - parent: undefined, - value: undefined - }, - undefined - ]); - - const nodeUndefined = bst.keyValueNodeEntryRawToNodeAndValue(undefined); - expect(nodeUndefined).toEqual([undefined, undefined]); - - const nodeNull = bst.keyValueNodeEntryRawToNodeAndValue(null); - expect(nodeNull).toEqual([undefined, undefined]); - }); + // it('should keyValueNodeEntryRawToNodeAndValue', () => { + // const bst = new BST([], { isMapMode: false }); + // const node0 = bst.keyValueNodeEntryRawToNodeAndValue(0); + // expect(node0).toEqual([ + // { + // _left: undefined, + // _right: undefined, + // key: 0, + // parent: undefined, + // value: undefined + // }, + // undefined + // ]); + // + // const nodeUndefined = bst.keyValueNodeEntryRawToNodeAndValue(undefined); + // expect(nodeUndefined).toEqual([undefined, undefined]); + // + // const nodeNull = bst.keyValueNodeEntryRawToNodeAndValue(null); + // expect(nodeNull).toEqual([undefined, undefined]); + // }); }); describe('BST operations not map mode test recursively', () => {