Skip to content

Commit

Permalink
fix: rename the keyValueNodeEntryRawToNodeAndValue to _keyValueNodeEn…
Browse files Browse the repository at this point in the history
…tryRawToNodeAndValue and make it protected
  • Loading branch information
zrwusa committed Nov 22, 2024
1 parent aab0c87 commit ca7e60e
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 127 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/data-structures/binary-tree/avl-tree-multi-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/data-structures/binary-tree/binary-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/data-structures/binary-tree/bst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/data-structures/binary-tree/rb-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/data-structures/binary-tree/tree-multi-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions src/data-structures/linked-list/doubly-linked-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 4 additions & 10 deletions src/data-structures/trie/trie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>([
Expand Down Expand Up @@ -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
Expand Down
70 changes: 35 additions & 35 deletions test/unit/data-structures/binary-tree/binary-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
Loading

0 comments on commit ca7e60e

Please sign in to comment.