data-structure-typed 1.38.5 → 1.38.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +14 -8
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +10 -5
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +59 -107
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +72 -81
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +13 -13
- package/dist/cjs/data-structures/binary-tree/bst.js +14 -14
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +15 -11
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js +11 -7
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/cjs/types/helpers.d.ts +2 -0
- package/dist/cjs/types/helpers.js.map +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +14 -8
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +10 -5
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +59 -107
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +72 -81
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +13 -13
- package/dist/mjs/data-structures/binary-tree/bst.js +14 -14
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +15 -11
- package/dist/mjs/data-structures/binary-tree/tree-multiset.js +11 -7
- package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
- package/dist/mjs/types/helpers.d.ts +2 -0
- package/dist/umd/index.global.js +1 -1
- package/dist/umd/index.global.js.map +1 -1
- package/package.json +5 -5
- package/src/data-structures/binary-tree/avl-tree.ts +22 -13
- package/src/data-structures/binary-tree/binary-tree.ts +155 -111
- package/src/data-structures/binary-tree/bst.ts +26 -26
- package/src/data-structures/binary-tree/rb-tree.ts +6 -9
- package/src/data-structures/binary-tree/tree-multiset.ts +24 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +0 -1
- package/src/interfaces/binary-tree.ts +3 -3
- package/src/types/helpers.ts +4 -0
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +15 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "1.38.
|
|
3
|
+
"version": "1.38.7",
|
|
4
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.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/mjs/index.js",
|
|
@@ -61,17 +61,17 @@
|
|
|
61
61
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
62
62
|
"@typescript-eslint/parser": "^6.7.4",
|
|
63
63
|
"auto-changelog": "^2.4.0",
|
|
64
|
-
"avl-tree-typed": "^1.38.
|
|
64
|
+
"avl-tree-typed": "^1.38.6",
|
|
65
65
|
"benchmark": "^2.1.4",
|
|
66
|
-
"binary-tree-typed": "^1.38.
|
|
67
|
-
"bst-typed": "^1.38.
|
|
66
|
+
"binary-tree-typed": "^1.38.6",
|
|
67
|
+
"bst-typed": "^1.38.6",
|
|
68
68
|
"dependency-cruiser": "^14.1.0",
|
|
69
69
|
"eslint": "^8.50.0",
|
|
70
70
|
"eslint-config-prettier": "^9.0.0",
|
|
71
71
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
72
72
|
"eslint-import-resolver-typescript": "^3.6.1",
|
|
73
73
|
"eslint-plugin-import": "^2.28.1",
|
|
74
|
-
"heap-typed": "^1.38.
|
|
74
|
+
"heap-typed": "^1.38.6",
|
|
75
75
|
"istanbul-badges-readme": "^1.8.5",
|
|
76
76
|
"jest": "^29.7.0",
|
|
77
77
|
"prettier": "^3.0.3",
|
|
@@ -7,12 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import {BST, BSTNode} from './bst';
|
|
9
9
|
import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeKey} from '../../types';
|
|
10
|
+
import {MapCallback} from '../../types';
|
|
10
11
|
import {IBinaryTree} from '../../interfaces';
|
|
11
12
|
|
|
12
|
-
export class AVLTreeNode<V = any,
|
|
13
|
-
V,
|
|
14
|
-
FAMILY
|
|
15
|
-
> {
|
|
13
|
+
export class AVLTreeNode<V = any, N extends AVLTreeNode<V, N> = AVLTreeNodeNested<V>> extends BSTNode<V, N> {
|
|
16
14
|
height: number;
|
|
17
15
|
|
|
18
16
|
constructor(key: BinaryTreeNodeKey, val?: V) {
|
|
@@ -21,7 +19,10 @@ export class AVLTreeNode<V = any, FAMILY extends AVLTreeNode<V, FAMILY> = AVLTre
|
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
export class AVLTree<N extends AVLTreeNode<
|
|
22
|
+
export class AVLTree<V = any, N extends AVLTreeNode<V, N> = AVLTreeNode>
|
|
23
|
+
extends BST<V, N>
|
|
24
|
+
implements IBinaryTree<V, N>
|
|
25
|
+
{
|
|
25
26
|
/**
|
|
26
27
|
* This is a constructor function for an AVL tree data structure in TypeScript.
|
|
27
28
|
* @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
|
|
@@ -37,12 +38,12 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
|
|
|
37
38
|
* @param {BinaryTreeNodeKey} key - The key parameter is the key value that will be associated with
|
|
38
39
|
* the new node. It is used to determine the position of the node in the binary search tree.
|
|
39
40
|
* @param [val] - The parameter `val` is an optional value that can be assigned to the node. It is of
|
|
40
|
-
* type `
|
|
41
|
+
* type `V`, which means it can be any value that is assignable to the `val` property of the
|
|
41
42
|
* node type `N`.
|
|
42
43
|
* @returns a new AVLTreeNode object with the specified key and value.
|
|
43
44
|
*/
|
|
44
|
-
override createNode(key: BinaryTreeNodeKey, val?:
|
|
45
|
-
return new AVLTreeNode<
|
|
45
|
+
override createNode(key: BinaryTreeNodeKey, val?: V): N {
|
|
46
|
+
return new AVLTreeNode<V, N>(key, val) as N;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/**
|
|
@@ -54,7 +55,7 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
|
|
|
54
55
|
* are adding to the binary search tree.
|
|
55
56
|
* @returns The method is returning the inserted node (`N`), `null`, or `undefined`.
|
|
56
57
|
*/
|
|
57
|
-
override add(keyOrNode: BinaryTreeNodeKey | N | null, val?:
|
|
58
|
+
override add(keyOrNode: BinaryTreeNodeKey | N | null, val?: V): N | null | undefined {
|
|
58
59
|
// TODO support node as a param
|
|
59
60
|
const inserted = super.add(keyOrNode, val);
|
|
60
61
|
if (inserted) this._balancePath(inserted);
|
|
@@ -64,12 +65,20 @@ export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends B
|
|
|
64
65
|
/**
|
|
65
66
|
* The function overrides the delete method of a binary tree and balances the tree after deleting a
|
|
66
67
|
* node if necessary.
|
|
67
|
-
* @param {
|
|
68
|
-
*
|
|
68
|
+
* @param {ReturnType<C>} identifier - The `identifier` parameter is either a
|
|
69
|
+
* `BinaryTreeNodeKey` or a generic type `N`. It represents the property of the node that we are
|
|
70
|
+
* searching for. It can be a specific key value or any other property of the node.
|
|
71
|
+
* @param callback - The `callback` parameter is a function that takes a node as input and returns a
|
|
72
|
+
* value. This value is compared with the `identifier` parameter to determine if the node should be
|
|
73
|
+
* included in the result. The `callback` parameter has a default value of
|
|
74
|
+
* `this._defaultCallbackByKey`
|
|
69
75
|
* @returns The method is returning an array of `BinaryTreeDeletedResult<N>` objects.
|
|
70
76
|
*/
|
|
71
|
-
override delete
|
|
72
|
-
|
|
77
|
+
override delete<C extends MapCallback<N>>(
|
|
78
|
+
identifier: ReturnType<C>,
|
|
79
|
+
callback: C = this._defaultCallbackByKey as C
|
|
80
|
+
): BinaryTreeDeletedResult<N>[] {
|
|
81
|
+
const deletedResults = super.delete(identifier, callback);
|
|
73
82
|
for (const {needBalanced} of deletedResults) {
|
|
74
83
|
if (needBalanced) {
|
|
75
84
|
this._balancePath(needBalanced);
|