data-structure-typed 1.18.5 → 1.18.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/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +357 -0
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +1480 -0
- package/dist/data-structures/binary-tree/avl-tree.d.ts +8 -6
- package/dist/data-structures/binary-tree/avl-tree.js +7 -5
- package/dist/data-structures/binary-tree/binary-tree.d.ts +19 -337
- package/dist/data-structures/binary-tree/binary-tree.js +40 -1441
- package/dist/data-structures/binary-tree/bst.d.ts +31 -17
- package/dist/data-structures/binary-tree/bst.js +57 -40
- package/dist/data-structures/binary-tree/index.d.ts +1 -0
- package/dist/data-structures/binary-tree/index.js +1 -0
- package/dist/data-structures/binary-tree/rb-tree.d.ts +30 -1
- package/dist/data-structures/binary-tree/rb-tree.js +29 -20
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +21 -25
- package/dist/data-structures/binary-tree/tree-multiset.js +40 -31
- package/dist/data-structures/graph/abstract-graph.d.ts +20 -21
- package/dist/data-structures/graph/abstract-graph.js +24 -19
- package/dist/data-structures/graph/directed-graph.d.ts +12 -13
- package/dist/data-structures/graph/directed-graph.js +21 -25
- package/dist/data-structures/graph/undirected-graph.d.ts +15 -19
- package/dist/data-structures/graph/undirected-graph.js +16 -29
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +101 -0
- package/dist/data-structures/interfaces/abstract-binary-tree.js +2 -0
- package/dist/data-structures/interfaces/abstract-graph.d.ts +1 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +16 -1
- package/dist/data-structures/interfaces/binary-tree.d.ts +4 -25
- package/dist/data-structures/interfaces/bst.d.ts +18 -1
- package/dist/data-structures/interfaces/directed-graph.d.ts +4 -1
- package/dist/data-structures/interfaces/index.d.ts +1 -1
- package/dist/data-structures/interfaces/index.js +1 -1
- package/dist/data-structures/interfaces/rb-tree.d.ts +9 -0
- package/dist/data-structures/interfaces/rb-tree.js +2 -0
- package/dist/data-structures/interfaces/undirected-graph.d.ts +4 -1
- package/dist/data-structures/types/abstract-binary-tree.d.ts +32 -0
- package/dist/data-structures/types/abstract-binary-tree.js +21 -0
- package/dist/data-structures/types/avl-tree.d.ts +2 -4
- package/dist/data-structures/types/binary-tree.d.ts +2 -10
- package/dist/data-structures/types/bst.d.ts +10 -5
- package/dist/data-structures/types/bst.js +7 -0
- package/dist/data-structures/types/helpers.d.ts +8 -0
- package/dist/data-structures/types/helpers.js +2 -0
- package/dist/data-structures/types/index.d.ts +3 -0
- package/dist/data-structures/types/index.js +3 -0
- package/dist/data-structures/types/rb-tree.d.ts +6 -0
- package/dist/data-structures/types/rb-tree.js +8 -0
- package/dist/data-structures/types/tree-multiset.d.ts +5 -3
- package/dist/utils/utils.js +62 -0
- package/docs/assets/search.js +1 -1
- package/docs/classes/AVLTree.html +316 -204
- package/docs/classes/AVLTreeNode.html +141 -81
- package/docs/classes/AaTree.html +27 -10
- package/docs/classes/AbstractBinaryTree.html +2118 -0
- package/docs/classes/AbstractBinaryTreeNode.html +524 -0
- package/docs/classes/AbstractEdge.html +37 -20
- package/docs/classes/AbstractGraph.html +152 -144
- package/docs/classes/AbstractVertex.html +34 -17
- package/docs/classes/ArrayDeque.html +40 -23
- package/docs/classes/BST.html +294 -187
- package/docs/classes/BSTNode.html +144 -82
- package/docs/classes/BTree.html +27 -10
- package/docs/classes/BinaryIndexedTree.html +35 -18
- package/docs/classes/BinaryTree.html +597 -500
- package/docs/classes/BinaryTreeNode.html +189 -168
- package/docs/classes/Character.html +30 -13
- package/docs/classes/CoordinateMap.html +35 -18
- package/docs/classes/CoordinateSet.html +34 -17
- package/docs/classes/Deque.html +60 -43
- package/docs/classes/DirectedEdge.html +41 -24
- package/docs/classes/DirectedGraph.html +208 -247
- package/docs/classes/DirectedVertex.html +32 -15
- package/docs/classes/DoublyLinkedList.html +63 -46
- package/docs/classes/DoublyLinkedListNode.html +37 -20
- package/docs/classes/HashTable.html +27 -10
- package/docs/classes/Heap.html +41 -24
- package/docs/classes/HeapItem.html +34 -17
- package/docs/classes/Matrix2D.html +42 -25
- package/docs/classes/MatrixNTI2D.html +30 -13
- package/docs/classes/MaxHeap.html +41 -24
- package/docs/classes/MaxPriorityQueue.html +60 -43
- package/docs/classes/MinHeap.html +41 -24
- package/docs/classes/MinPriorityQueue.html +60 -43
- package/docs/classes/Navigator.html +36 -19
- package/docs/classes/ObjectDeque.html +51 -34
- package/docs/classes/Pair.html +27 -10
- package/docs/classes/PriorityQueue.html +58 -41
- package/docs/classes/Queue.html +40 -23
- package/docs/classes/RBTree.html +2388 -0
- package/docs/classes/RBTreeNode.html +516 -0
- package/docs/classes/SegmentTree.html +43 -26
- package/docs/classes/SegmentTreeNode.html +46 -29
- package/docs/classes/SinglyLinkedList.html +60 -43
- package/docs/classes/SinglyLinkedListNode.html +34 -17
- package/docs/classes/SkipLinkedList.html +27 -10
- package/docs/classes/SplayTree.html +27 -10
- package/docs/classes/Stack.html +38 -21
- package/docs/classes/TreeMap.html +27 -10
- package/docs/classes/TreeMultiSet.html +332 -224
- package/docs/classes/TreeMultiSetNode.html +499 -0
- package/docs/classes/TreeNode.html +42 -25
- package/docs/classes/TreeSet.html +27 -10
- package/docs/classes/Trie.html +39 -22
- package/docs/classes/TrieNode.html +37 -20
- package/docs/classes/TwoThreeTree.html +27 -10
- package/docs/classes/UndirectedEdge.html +38 -21
- package/docs/classes/UndirectedGraph.html +179 -227
- package/docs/classes/UndirectedVertex.html +32 -15
- package/docs/classes/Vector2D.html +54 -37
- package/docs/enums/CP.html +33 -16
- package/docs/enums/FamilyPosition.html +45 -28
- package/docs/enums/LoopType.html +39 -22
- package/docs/{interfaces/IBinaryTree.html → enums/RBColor.html} +51 -54
- package/docs/enums/TopologicalProperty.html +30 -13
- package/docs/index.html +26 -9
- package/docs/interfaces/IAVLTree.html +1378 -0
- package/docs/interfaces/IAVLTreeNode.html +405 -0
- package/docs/interfaces/IAbstractBinaryTree.html +1124 -0
- package/docs/interfaces/{IBinaryTreeNode.html → IAbstractBinaryTreeNode.html} +76 -75
- package/docs/interfaces/{IGraph.html → IAbstractGraph.html} +67 -94
- package/docs/interfaces/IBST.html +1271 -0
- package/docs/interfaces/IBSTNode.html +408 -0
- package/docs/interfaces/IDirectedGraph.html +344 -20
- package/docs/interfaces/IUNDirectedGraph.html +337 -12
- package/docs/modules.html +52 -18
- package/docs/types/{AVLTreeDeleted.html → AVLTreeOptions.html} +32 -24
- package/docs/types/{ResultsByProperty.html → AbstractBinaryTreeNodeProperties.html} +32 -15
- package/docs/types/AbstractBinaryTreeNodeProperty.html +152 -0
- package/docs/types/AbstractBinaryTreeOptions.html +156 -0
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +152 -0
- package/docs/types/BSTComparator.html +27 -10
- package/docs/types/{TreeMultiSetDeletedResult.html → BSTOptions.html} +32 -22
- package/docs/types/BinaryTreeDeletedResult.html +159 -0
- package/docs/types/BinaryTreeNodeId.html +27 -10
- package/docs/types/BinaryTreeNodePropertyName.html +27 -10
- package/docs/types/{BinaryTreeDeleted.html → BinaryTreeOptions.html} +32 -24
- package/docs/types/DFSOrderPattern.html +27 -10
- package/docs/types/DijkstraResult.html +27 -10
- package/docs/types/Direction.html +27 -10
- package/docs/types/EdgeId.html +27 -10
- package/docs/types/HeapOptions.html +27 -10
- package/docs/types/IdObject.html +157 -0
- package/docs/types/{ResultByProperty.html → KeyValObject.html} +36 -19
- package/docs/types/NavigatorParams.html +27 -10
- package/docs/types/NodeOrPropertyName.html +27 -10
- package/docs/types/PriorityQueueComparator.html +27 -10
- package/docs/types/PriorityQueueDFSOrderPattern.html +27 -10
- package/docs/types/PriorityQueueOptions.html +27 -10
- package/docs/types/{BSTDeletedResult.html → RBTreeOptions.html} +32 -24
- package/docs/types/RecursiveAVLTreeNode.html +27 -10
- package/docs/types/RecursiveBSTNode.html +27 -10
- package/docs/types/RecursiveBinaryTreeNode.html +27 -10
- package/docs/types/RecursiveTreeMultiSetNode.html +152 -0
- package/docs/types/SegmentTreeNodeVal.html +27 -10
- package/docs/types/TopologicalStatus.html +27 -10
- package/docs/types/TreeMultiSetOptions.html +152 -0
- package/docs/types/Turning.html +27 -10
- package/docs/types/VertexId.html +27 -10
- package/package.json +2 -2
|
@@ -6,12 +6,14 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import { BST, BSTNode } from './bst';
|
|
9
|
-
import type {
|
|
10
|
-
import {
|
|
11
|
-
export declare class AVLTreeNode<T, FAMILY extends AVLTreeNode<T, FAMILY> = RecursiveAVLTreeNode<T>> extends BSTNode<T, FAMILY> implements
|
|
9
|
+
import type { AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId, RecursiveAVLTreeNode } from '../types';
|
|
10
|
+
import { IAVLTree, IAVLTreeNode } from '../interfaces';
|
|
11
|
+
export declare class AVLTreeNode<T, FAMILY extends AVLTreeNode<T, FAMILY> = RecursiveAVLTreeNode<T>> extends BSTNode<T, FAMILY> implements IAVLTreeNode<T, FAMILY> {
|
|
12
|
+
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
12
13
|
}
|
|
13
|
-
export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<number>> extends BST<N> {
|
|
14
|
-
|
|
14
|
+
export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<number>> extends BST<N> implements IAVLTree<N> {
|
|
15
|
+
constructor(options?: AVLTreeOptions);
|
|
16
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
15
17
|
/**
|
|
16
18
|
* The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
|
|
17
19
|
* balances the tree.
|
|
@@ -35,7 +37,7 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<nu
|
|
|
35
37
|
* `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
|
|
36
38
|
* @returns The method is returning an array of `AVLTreeDeleted<N>` objects.
|
|
37
39
|
*/
|
|
38
|
-
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean):
|
|
40
|
+
remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[];
|
|
39
41
|
/**
|
|
40
42
|
* The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
|
|
41
43
|
* height of its right subtree.
|
|
@@ -40,17 +40,19 @@ var AVLTreeNode = /** @class */ (function (_super) {
|
|
|
40
40
|
function AVLTreeNode() {
|
|
41
41
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
42
42
|
}
|
|
43
|
+
AVLTreeNode.prototype.createNode = function (id, val, count) {
|
|
44
|
+
return new AVLTreeNode(id, (val === undefined ? id : val), count);
|
|
45
|
+
};
|
|
43
46
|
return AVLTreeNode;
|
|
44
47
|
}(bst_1.BSTNode));
|
|
45
48
|
exports.AVLTreeNode = AVLTreeNode;
|
|
46
49
|
var AVLTree = /** @class */ (function (_super) {
|
|
47
50
|
__extends(AVLTree, _super);
|
|
48
|
-
function AVLTree() {
|
|
49
|
-
return _super
|
|
51
|
+
function AVLTree(options) {
|
|
52
|
+
return _super.call(this, options) || this;
|
|
50
53
|
}
|
|
51
|
-
AVLTree.prototype.
|
|
52
|
-
|
|
53
|
-
return node;
|
|
54
|
+
AVLTree.prototype.createNode = function (id, val, count) {
|
|
55
|
+
return new AVLTreeNode(id, (val === undefined ? id : val), count);
|
|
54
56
|
};
|
|
55
57
|
/**
|
|
56
58
|
* The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
|
|
@@ -5,88 +5,30 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
export declare class BinaryTreeNode<T, FAMILY extends BinaryTreeNode<T, FAMILY> = RecursiveBinaryTreeNode<T>> implements IBinaryTreeNode<T, FAMILY> {
|
|
26
|
-
constructor(id: BinaryTreeNodeId, val: T, count?: number);
|
|
27
|
-
private _id;
|
|
28
|
-
get id(): BinaryTreeNodeId;
|
|
29
|
-
set id(v: BinaryTreeNodeId);
|
|
30
|
-
private _val;
|
|
31
|
-
get val(): T;
|
|
32
|
-
set val(v: T);
|
|
33
|
-
private _left?;
|
|
34
|
-
get left(): FAMILY | null | undefined;
|
|
35
|
-
set left(v: FAMILY | null | undefined);
|
|
36
|
-
private _right?;
|
|
37
|
-
get right(): FAMILY | null | undefined;
|
|
38
|
-
set right(v: FAMILY | null | undefined);
|
|
39
|
-
private _parent;
|
|
40
|
-
get parent(): FAMILY | null | undefined;
|
|
41
|
-
set parent(v: FAMILY | null | undefined);
|
|
42
|
-
private _familyPosition;
|
|
43
|
-
get familyPosition(): FamilyPosition;
|
|
44
|
-
set familyPosition(v: FamilyPosition);
|
|
45
|
-
private _count;
|
|
46
|
-
get count(): number;
|
|
47
|
-
set count(v: number);
|
|
48
|
-
private _height;
|
|
49
|
-
get height(): number;
|
|
50
|
-
set height(v: number);
|
|
51
|
-
_createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
|
|
52
|
-
swapLocation(swapNode: FAMILY): FAMILY;
|
|
53
|
-
clone(): FAMILY | null;
|
|
8
|
+
import type { BinaryTreeNodeId, RecursiveBinaryTreeNode } from '../types';
|
|
9
|
+
import { BinaryTreeOptions } from '../types';
|
|
10
|
+
import { AbstractBinaryTree, AbstractBinaryTreeNode } from './abstract-binary-tree';
|
|
11
|
+
import { IBinaryTree, IBinaryTreeNode } from '../interfaces/binary-tree';
|
|
12
|
+
export declare class BinaryTreeNode<T = number, FAMILY extends BinaryTreeNode<T, FAMILY> = RecursiveBinaryTreeNode<T>> extends AbstractBinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
|
|
13
|
+
/**
|
|
14
|
+
* The function creates a new binary tree node with an optional value and count, and returns it as a specified type.
|
|
15
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
|
|
16
|
+
* `BinaryTreeNodeId`, which could be a string or a number depending on how you want to identify your nodes.
|
|
17
|
+
* @param {T} [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the
|
|
18
|
+
* value stored in the node.
|
|
19
|
+
* @param {number} [count] - The count parameter is an optional parameter that represents the number of times the value
|
|
20
|
+
* appears in the binary tree node.
|
|
21
|
+
* @returns a new instance of the BinaryTreeNode class, casted as the FAMILY type.
|
|
22
|
+
*/
|
|
23
|
+
createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
54
24
|
}
|
|
55
|
-
export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode<
|
|
25
|
+
export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode> extends AbstractBinaryTree<N> implements IBinaryTree<N> {
|
|
56
26
|
/**
|
|
57
27
|
* The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and
|
|
58
28
|
* isDuplicatedVal based on the provided options.
|
|
59
29
|
* @param [options] - An optional object that can contain the following properties:
|
|
60
30
|
*/
|
|
61
|
-
constructor(options?:
|
|
62
|
-
loopType?: LoopType;
|
|
63
|
-
autoIncrementId?: boolean;
|
|
64
|
-
isDuplicatedVal?: boolean;
|
|
65
|
-
});
|
|
66
|
-
private _loopType;
|
|
67
|
-
get loopType(): LoopType;
|
|
68
|
-
private _visitedId;
|
|
69
|
-
get visitedId(): BinaryTreeNodeId[];
|
|
70
|
-
private _visitedVal;
|
|
71
|
-
get visitedVal(): Array<N['val']>;
|
|
72
|
-
private _visitedNode;
|
|
73
|
-
get visitedNode(): N[];
|
|
74
|
-
private _visitedCount;
|
|
75
|
-
get visitedCount(): number[];
|
|
76
|
-
private _visitedLeftSum;
|
|
77
|
-
get visitedLeftSum(): number[];
|
|
78
|
-
private _autoIncrementId;
|
|
79
|
-
get autoIncrementId(): boolean;
|
|
80
|
-
private _maxId;
|
|
81
|
-
get maxId(): number;
|
|
82
|
-
private _isDuplicatedVal;
|
|
83
|
-
get isDuplicatedVal(): boolean;
|
|
84
|
-
private _root;
|
|
85
|
-
get root(): N | null;
|
|
86
|
-
private _size;
|
|
87
|
-
get size(): number;
|
|
88
|
-
private _count;
|
|
89
|
-
get count(): number;
|
|
31
|
+
constructor(options?: BinaryTreeOptions);
|
|
90
32
|
/**
|
|
91
33
|
* The function creates a new binary tree node with the given id, value, and count if the value is not null, otherwise
|
|
92
34
|
* it returns null.
|
|
@@ -98,265 +40,5 @@ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTr
|
|
|
98
40
|
* of occurrences of the value in the binary tree node. If not provided, the default value is `undefined`.
|
|
99
41
|
* @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
|
|
100
42
|
*/
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* The clear function resets the state of an object by setting its properties to their initial values.
|
|
104
|
-
*/
|
|
105
|
-
clear(): void;
|
|
106
|
-
/**
|
|
107
|
-
* The function checks if the size of an object is equal to zero and returns a boolean value.
|
|
108
|
-
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
|
109
|
-
*/
|
|
110
|
-
isEmpty(): boolean;
|
|
111
|
-
/**
|
|
112
|
-
* The `add` function inserts a new node with a given ID and value into a binary tree, updating the count if the node
|
|
113
|
-
* already exists.
|
|
114
|
-
* @param {BinaryTreeNodeId} id - The id parameter is the identifier of the binary tree node. It is used to uniquely
|
|
115
|
-
* identify each node in the binary tree.
|
|
116
|
-
* @param {N} val - The value to be inserted into the binary tree.
|
|
117
|
-
* @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
|
|
118
|
-
* value should be inserted into the binary tree. If not provided, it defaults to 1.
|
|
119
|
-
* @returns The function `add` returns a `N` object if a new node is inserted, or `null` if no new node
|
|
120
|
-
* is inserted, or `undefined` if the insertion fails.
|
|
121
|
-
*/
|
|
122
|
-
add(id: BinaryTreeNodeId, val: N['val'], count?: number): N | null | undefined;
|
|
123
|
-
/**
|
|
124
|
-
* The function inserts a new node into a binary tree as the left or right child of a given parent node.
|
|
125
|
-
* @param {N | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
|
|
126
|
-
* `null`. It represents the node that needs to be inserted into the binary tree.
|
|
127
|
-
* @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node
|
|
128
|
-
* will be inserted as a child.
|
|
129
|
-
* @returns The method returns the newly inserted node, either as the left child or the right child of the parent node.
|
|
130
|
-
*/
|
|
131
|
-
addTo(newNode: N | null, parent: N): N | null | undefined;
|
|
132
|
-
/**
|
|
133
|
-
* The `addMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
|
|
134
|
-
* null/undefined values.
|
|
135
|
-
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
|
|
136
|
-
* array of `N` objects.
|
|
137
|
-
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
138
|
-
*/
|
|
139
|
-
addMany(data: N[] | Array<N['val']>): (N | null | undefined)[];
|
|
140
|
-
/**
|
|
141
|
-
* The `fill` function clears the current data and inserts new data, returning a boolean indicating if the insertion
|
|
142
|
-
* was successful.
|
|
143
|
-
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
|
|
144
|
-
* array of `N` objects.
|
|
145
|
-
* @returns The method is returning a boolean value.
|
|
146
|
-
*/
|
|
147
|
-
fill(data: N[] | Array<N['val']>): boolean;
|
|
148
|
-
/**
|
|
149
|
-
* The function removes a node from a binary tree and returns information about the deleted node.
|
|
150
|
-
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to remove.
|
|
151
|
-
* It is of type `BinaryTreeNodeId`.
|
|
152
|
-
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
|
|
153
|
-
* whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
|
|
154
|
-
* not be decremented and the overall count of the binary tree will not be updated. If `
|
|
155
|
-
* @returns An array of objects is being returned. Each object in the array has two properties: "deleted" and
|
|
156
|
-
* "needBalanced". The "deleted" property contains the deleted node or undefined if no node was deleted. The
|
|
157
|
-
* "needBalanced" property is always null.
|
|
158
|
-
*/
|
|
159
|
-
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<N>[];
|
|
160
|
-
/**
|
|
161
|
-
* The function calculates the depth of a binary tree node by traversing its parent nodes.
|
|
162
|
-
* @param node - N - This is the node for which we want to calculate the depth. It is a generic type,
|
|
163
|
-
* meaning it can represent any type of data that we want to store in the node.
|
|
164
|
-
* @returns The depth of the given binary tree node.
|
|
165
|
-
*/
|
|
166
|
-
getDepth(node: N): number;
|
|
167
|
-
/**
|
|
168
|
-
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive or iterative
|
|
169
|
-
* approach.
|
|
170
|
-
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
|
|
171
|
-
* `N | null`. It represents the starting node from which to calculate the height of the binary tree.
|
|
172
|
-
* If no value is provided for `beginRoot`, the function will use the `root` property of the class instance as
|
|
173
|
-
* @returns the height of the binary tree.
|
|
174
|
-
*/
|
|
175
|
-
getHeight(beginRoot?: N | null): number;
|
|
176
|
-
/**
|
|
177
|
-
* The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
|
|
178
|
-
* approach.
|
|
179
|
-
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
|
|
180
|
-
* `N | null`. It represents the starting node from which to calculate the minimum height of the binary
|
|
181
|
-
* tree. If no value is provided for `beginRoot`, the function will use the root node of the binary tree.
|
|
182
|
-
* @returns The function `getMinHeight` returns the minimum height of the binary tree.
|
|
183
|
-
*/
|
|
184
|
-
getMinHeight(beginRoot?: N | null): number;
|
|
185
|
-
/**
|
|
186
|
-
* The function checks if a binary tree is balanced by comparing the minimum height and the maximum height of the tree.
|
|
187
|
-
* @param {N | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
|
|
188
|
-
* of type `N | null`, which means it can either be a `BinaryTreeNode` object or `null`.
|
|
189
|
-
* @returns The method is returning a boolean value.
|
|
190
|
-
*/
|
|
191
|
-
isBalanced(beginRoot?: N | null): boolean;
|
|
192
|
-
/**
|
|
193
|
-
* The function `getNodes` returns an array of binary tree nodes that match a given property value, with options for
|
|
194
|
-
* searching recursively or iteratively.
|
|
195
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
196
|
-
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
197
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
198
|
-
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
|
|
199
|
-
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
200
|
-
* return only one node that matches the `nodeProperty` or `propertyName` criteria. If `onlyOne` is set to `true`, the
|
|
201
|
-
* function will stop traversing the tree and return the first matching node. If `
|
|
202
|
-
* @returns The function `getNodes` returns an array of `N | null | undefined` objects.
|
|
203
|
-
*/
|
|
204
|
-
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): (N | null | undefined)[];
|
|
205
|
-
/**
|
|
206
|
-
* The function checks if a binary tree node has a specific property or if any node in the tree has a specific
|
|
207
|
-
* property.
|
|
208
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
209
|
-
* generic type `N`. It represents the property of a binary tree node that you want to check.
|
|
210
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
211
|
-
* specifies the name of the property to check for in the nodes.
|
|
212
|
-
* @returns a boolean value.
|
|
213
|
-
*/
|
|
214
|
-
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
215
|
-
/**
|
|
216
|
-
* The function returns the first binary tree node that matches the given property name and value, or null if no match
|
|
217
|
-
* is found.
|
|
218
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
219
|
-
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
220
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
221
|
-
* specifies the property of the binary tree node to search for. If not provided, it defaults to `'id'`.
|
|
222
|
-
* @returns a BinaryTreeNode object or null.
|
|
223
|
-
*/
|
|
224
|
-
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
225
|
-
/**
|
|
226
|
-
* The function getPathToRoot returns an array of BinaryTreeNode objects representing the path from a given node to the
|
|
227
|
-
* root of a binary tree.
|
|
228
|
-
* @param node - The `node` parameter is a BinaryTreeNode object.
|
|
229
|
-
* @returns The function `getPathToRoot` returns an array of `N` objects, representing the path from
|
|
230
|
-
* the given `node` to the root of the binary tree.
|
|
231
|
-
*/
|
|
232
|
-
getPathToRoot(node: N): N[];
|
|
233
|
-
getLeftMost(): N | null;
|
|
234
|
-
getLeftMost(node: N): N;
|
|
235
|
-
getRightMost(): N | null;
|
|
236
|
-
getRightMost(node: N): N;
|
|
237
|
-
/**
|
|
238
|
-
* The `isBST` function checks if a binary tree is a binary search tree.
|
|
239
|
-
* @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
|
|
240
|
-
* | null`. It represents the root node of the binary search tree (BST) that we want to check for validity. If no node
|
|
241
|
-
* is provided, the function will default to using the root node of the BST instance that
|
|
242
|
-
* @returns The `isBST` function returns a boolean value. It returns `true` if the binary tree is a valid binary search
|
|
243
|
-
* tree, and `false` otherwise.
|
|
244
|
-
*/
|
|
245
|
-
isBST(node?: N | null): boolean;
|
|
246
|
-
/**
|
|
247
|
-
* The function calculates the size and count of a subtree in a binary tree using either recursive or iterative
|
|
248
|
-
* traversal.
|
|
249
|
-
* @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
|
|
250
|
-
* tree.
|
|
251
|
-
* @returns The function `getSubTreeSizeAndCount` returns an array `[number, number]`. The first element of the array
|
|
252
|
-
* represents the size of the subtree, and the second element represents the count of the nodes in the subtree.
|
|
253
|
-
*/
|
|
254
|
-
getSubTreeSizeAndCount(subTreeRoot: N | null | undefined): [number, number];
|
|
255
|
-
/**
|
|
256
|
-
* The function `subTreeSum` calculates the sum of a specified property in a binary tree, either recursively or
|
|
257
|
-
* iteratively.
|
|
258
|
-
* @param subTreeRoot - The subTreeRoot parameter is the root node of the subtree for which you want to calculate the
|
|
259
|
-
* sum.
|
|
260
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
261
|
-
* specifies the property of the `BinaryTreeNode` object to use for calculating the sum. If `propertyName` is not
|
|
262
|
-
* provided, it defaults to `'val'`.
|
|
263
|
-
* @returns a number, which is the sum of the values of the nodes in the subtree rooted at `subTreeRoot`.
|
|
264
|
-
*/
|
|
265
|
-
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
|
266
|
-
/**
|
|
267
|
-
* The function `subTreeAdd` adds a specified delta value to a property of each node in a binary tree.
|
|
268
|
-
* @param subTreeRoot - The `subTreeRoot` parameter is the root node of the subtree where the values will be modified.
|
|
269
|
-
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
270
|
-
* each node in the subtree should be increased or decreased.
|
|
271
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
272
|
-
* specifies the property of the `BinaryTreeNode` that should be modified. It defaults to `'id'` if not provided.
|
|
273
|
-
* @returns a boolean value, which is `true`.
|
|
274
|
-
*/
|
|
275
|
-
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
276
|
-
BFS(): BinaryTreeNodeId[];
|
|
277
|
-
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
|
|
278
|
-
BFS(nodeOrPropertyName: 'val'): N['val'][];
|
|
279
|
-
BFS(nodeOrPropertyName: 'node'): N[];
|
|
280
|
-
BFS(nodeOrPropertyName: 'count'): number[];
|
|
281
|
-
DFS(): BinaryTreeNodeId[];
|
|
282
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
283
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
284
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
285
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
286
|
-
DFSIterative(): BinaryTreeNodeId[];
|
|
287
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
288
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
289
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
290
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
291
|
-
levelIterative(node: N | null): BinaryTreeNodeId[];
|
|
292
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
293
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
|
294
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
|
295
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
|
296
|
-
listLevels(node: N | null): BinaryTreeNodeId[][];
|
|
297
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
|
|
298
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
|
299
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
|
300
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
|
301
|
-
/**
|
|
302
|
-
* The function returns the predecessor of a given node in a binary tree.
|
|
303
|
-
* @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
|
|
304
|
-
* @returns the predecessor of the given node in a binary tree.
|
|
305
|
-
*/
|
|
306
|
-
getPredecessor(node: N): N;
|
|
307
|
-
morris(): BinaryTreeNodeId[];
|
|
308
|
-
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
309
|
-
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
310
|
-
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
311
|
-
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
312
|
-
protected _setLoopType(value: LoopType): void;
|
|
313
|
-
protected _setVisitedId(value: BinaryTreeNodeId[]): void;
|
|
314
|
-
protected _setVisitedVal(value: Array<N>): void;
|
|
315
|
-
protected _setVisitedNode(value: N[]): void;
|
|
316
|
-
protected setVisitedCount(value: number[]): void;
|
|
317
|
-
protected _setVisitedLeftSum(value: number[]): void;
|
|
318
|
-
protected _setAutoIncrementId(value: boolean): void;
|
|
319
|
-
protected _setMaxId(value: number): void;
|
|
320
|
-
protected _setIsDuplicatedVal(value: boolean): void;
|
|
321
|
-
protected _setRoot(v: N | null): void;
|
|
322
|
-
protected _setSize(v: number): void;
|
|
323
|
-
protected _setCount(v: number): void;
|
|
324
|
-
/**
|
|
325
|
-
* The function resets the values of several arrays used for tracking visited nodes and their properties.
|
|
326
|
-
*/
|
|
327
|
-
protected _resetResults(): void;
|
|
328
|
-
/**
|
|
329
|
-
* The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
|
|
330
|
-
* a result array.
|
|
331
|
-
* @param cur - The current binary tree node that is being checked.
|
|
332
|
-
* @param {(N | null | undefined)[]} result - An array that stores the matching nodes found during the
|
|
333
|
-
* traversal.
|
|
334
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
|
|
335
|
-
* the binary tree nodes. It can be either the `id`, `count`, or `val` property of the node.
|
|
336
|
-
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
337
|
-
* specifies the property of the `BinaryTreeNode` object that you want to compare with the `nodeProperty` value. It can
|
|
338
|
-
* be one of the following values: 'id', 'count', or 'val'. If no `propertyName` is provided,
|
|
339
|
-
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
340
|
-
* stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
|
|
341
|
-
* `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
|
|
342
|
-
* @returns a boolean value indicating whether or not a node was pushed into the result array.
|
|
343
|
-
*/
|
|
344
|
-
protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
|
|
345
|
-
/**
|
|
346
|
-
* The function `_accumulatedByPropertyName` pushes a property value of a binary tree node into an array based on the
|
|
347
|
-
* provided property name or a default property name.
|
|
348
|
-
* @param node - The `node` parameter is of type `N`, which represents a node in a binary tree.
|
|
349
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
|
|
350
|
-
* can be either a string representing a property name or a reference to a node object. If it is a string, it specifies
|
|
351
|
-
* the property name of the node that should be accumulated. If it is a node object, it specifies the node itself
|
|
352
|
-
*/
|
|
353
|
-
protected _accumulatedByPropertyName(node: N, nodeOrPropertyName?: NodeOrPropertyName): void;
|
|
354
|
-
/**
|
|
355
|
-
* The function `_getResultByPropertyName` returns different results based on the provided property name or defaulting
|
|
356
|
-
* to 'id'.
|
|
357
|
-
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
|
|
358
|
-
* can accept a value of type `NodeOrPropertyName`.
|
|
359
|
-
* @returns The method returns an object of type `ResultsByProperty<T>`.
|
|
360
|
-
*/
|
|
361
|
-
protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<N>;
|
|
43
|
+
createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
|
|
362
44
|
}
|