fix: rename the keyValueNodeEntryRawToNodeAndValue to _keyValueNodeEntryRawToNodeAndValue and make it protected

This commit is contained in:
Revone 2024-11-22 22:55:43 +13:00
parent aab0c87da0
commit ca7e60e465
12 changed files with 131 additions and 127 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.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

52
package-lock.json generated
View file

@ -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": {

View file

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

View file

@ -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<K, V, NODE> | R,
value?: V,
count = 1
@ -217,7 +217,7 @@ export class AVLTreeMultiMap<
* @returns a boolean value.
*/
override add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | 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;

View file

@ -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<K, V, NODE> | R,
value?: V
): [OptNodeOrNull<NODE>, V | undefined] {
@ -420,7 +420,7 @@ export class BinaryTree<
* key was found and the node was replaced instead of inserted.
*/
add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | 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

View file

@ -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<K, V, NODE> | R,
value?: V
): [OptNode<NODE>, 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<K, V, NODE> | 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) {

View file

@ -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<K, V, NODE> | 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);

View file

@ -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<K, V, NODE> | R,
value?: V,
count = 1
@ -212,7 +212,7 @@ export class TreeMultiMap<
* was successful, and false otherwise.
*/
override add(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | 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);

View file

@ -514,6 +514,16 @@ export class DoublyLinkedListNode<E = any> {
* console.log(scheduler.listProcesses()); // []
*/
export class DoublyLinkedList<E = any, R = any> extends IterableElementBase<E, R, DoublyLinkedList<E, R>> {
/**
* This TypeScript constructor initializes a DoublyLinkedList with optional elements and options.
* @param {Iterable<E> | Iterable<R>} 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<E, R>`. It is an optional parameter that allows you to pass additional
* configuration options to customize the behavior of the DoublyLinkedList.
*/
constructor(elements: Iterable<E> | Iterable<R> = [], options?: DoublyLinkedListOptions<E, R>) {
super(options);
this._head = undefined;

View file

@ -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<string>([
* 'gmail.com',
* 'gmail.co.nz',
* 'gmail.co.jp',
* 'yahoo.com',
* 'outlook.com'
* ]);
* const autocomplete = new Trie<string>(['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<string>([
@ -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

View file

@ -733,41 +733,41 @@ describe('BinaryTree', () => {
]);
});
it('should keyValueNodeEntryRawToNodeAndValue', () => {
const tree = new BinaryTree<number>();
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<number, number, { obj: { id: number } }>([], {
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<number>();
// 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<number, number, { obj: { id: number } }>([], {
// 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<number, string>([4, 5, [1, '1'], 2, 3], { isMapMode: false });

View file

@ -450,26 +450,26 @@ describe('BST operations test', () => {
expect(bfsNodes[2].key).toBe(16);
});
it('should keyValueNodeEntryRawToNodeAndValue', () => {
const bst = new BST<number>();
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<number>();
// 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<number, string>([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<number>([], { 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<number>([], { 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', () => {