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
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* data-structure-typed
|
|
3
|
+
*
|
|
4
|
+
* @author Tyler Zeng
|
|
5
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
|
+
* @license MIT License
|
|
7
|
+
*/
|
|
8
|
+
import type { AbstractBinaryTreeNodeProperties, AbstractRecursiveBinaryTreeNode, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName } from '../types';
|
|
9
|
+
import { AbstractBinaryTreeOptions, FamilyPosition, LoopType } from '../types';
|
|
10
|
+
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from '../interfaces';
|
|
11
|
+
export declare abstract class AbstractBinaryTreeNode<T = number, FAMILY extends AbstractBinaryTreeNode<T, FAMILY> = AbstractRecursiveBinaryTreeNode<T>> implements IAbstractBinaryTreeNode<T, FAMILY> {
|
|
12
|
+
/**
|
|
13
|
+
* The constructor function initializes a BinaryTreeNode object with an id, value, and count.
|
|
14
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
|
|
15
|
+
* for the binary tree node.
|
|
16
|
+
* @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value of the binary
|
|
17
|
+
* tree node. If no value is provided, it will be `undefined`.
|
|
18
|
+
* @param {number} [count] - The `count` parameter is an optional parameter that represents the number of times the
|
|
19
|
+
* value `val` appears in the binary tree node. If the `count` parameter is not provided, it defaults to 1.
|
|
20
|
+
*/
|
|
21
|
+
constructor(id: BinaryTreeNodeId, val?: T, count?: number);
|
|
22
|
+
private _id;
|
|
23
|
+
get id(): BinaryTreeNodeId;
|
|
24
|
+
set id(v: BinaryTreeNodeId);
|
|
25
|
+
private _val;
|
|
26
|
+
get val(): T | undefined;
|
|
27
|
+
set val(value: T | undefined);
|
|
28
|
+
private _left?;
|
|
29
|
+
get left(): FAMILY | null | undefined;
|
|
30
|
+
set left(v: FAMILY | null | undefined);
|
|
31
|
+
private _right?;
|
|
32
|
+
get right(): FAMILY | null | undefined;
|
|
33
|
+
set right(v: FAMILY | null | undefined);
|
|
34
|
+
private _parent;
|
|
35
|
+
get parent(): FAMILY | null | undefined;
|
|
36
|
+
set parent(v: FAMILY | null | undefined);
|
|
37
|
+
private _familyPosition;
|
|
38
|
+
get familyPosition(): FamilyPosition;
|
|
39
|
+
set familyPosition(v: FamilyPosition);
|
|
40
|
+
private _count;
|
|
41
|
+
get count(): number;
|
|
42
|
+
set count(v: number);
|
|
43
|
+
private _height;
|
|
44
|
+
get height(): number;
|
|
45
|
+
set height(v: number);
|
|
46
|
+
abstract createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
|
|
47
|
+
/**
|
|
48
|
+
* The function swaps the location of two nodes in a binary tree.
|
|
49
|
+
* @param {FAMILY} swapNode - The `swapNode` parameter is of type `FAMILY`, which represents a node in a family tree.
|
|
50
|
+
* @returns the `swapNode` object after swapping its properties with the properties of `this` object.
|
|
51
|
+
*/
|
|
52
|
+
swapLocation(swapNode: FAMILY): FAMILY;
|
|
53
|
+
/**
|
|
54
|
+
* The `clone` function returns a new instance of the `FAMILY` class with the same `id`, `val`, and `count` properties.
|
|
55
|
+
* @returns The `clone()` method is returning a new instance of the `FAMILY` class with the same `id`, `val`, and
|
|
56
|
+
* `count` values as the current instance.
|
|
57
|
+
*/
|
|
58
|
+
clone(): FAMILY | null;
|
|
59
|
+
}
|
|
60
|
+
export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N> = AbstractBinaryTreeNode<number>> implements IAbstractBinaryTree<N> {
|
|
61
|
+
/**
|
|
62
|
+
* The protected constructor initializes the options for an abstract binary tree.
|
|
63
|
+
* @param {AbstractBinaryTreeOptions} [options] - An optional object that contains configuration options for the binary
|
|
64
|
+
* tree.
|
|
65
|
+
*/
|
|
66
|
+
protected constructor(options?: AbstractBinaryTreeOptions);
|
|
67
|
+
private _loopType;
|
|
68
|
+
get loopType(): LoopType;
|
|
69
|
+
private _visitedId;
|
|
70
|
+
get visitedId(): BinaryTreeNodeId[];
|
|
71
|
+
private _visitedVal;
|
|
72
|
+
get visitedVal(): Array<N['val']>;
|
|
73
|
+
private _visitedNode;
|
|
74
|
+
get visitedNode(): N[];
|
|
75
|
+
private _visitedCount;
|
|
76
|
+
get visitedCount(): number[];
|
|
77
|
+
private _visitedLeftSum;
|
|
78
|
+
get visitedLeftSum(): number[];
|
|
79
|
+
private _autoIncrementId;
|
|
80
|
+
get autoIncrementId(): boolean;
|
|
81
|
+
private _maxId;
|
|
82
|
+
get maxId(): number;
|
|
83
|
+
private _isDuplicatedVal;
|
|
84
|
+
get isDuplicatedVal(): boolean;
|
|
85
|
+
private _root;
|
|
86
|
+
get root(): N | null;
|
|
87
|
+
private _size;
|
|
88
|
+
get size(): number;
|
|
89
|
+
private _count;
|
|
90
|
+
get count(): number;
|
|
91
|
+
abstract createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
92
|
+
/**
|
|
93
|
+
* The clear function resets the state of an object by setting its properties to their initial values.
|
|
94
|
+
*/
|
|
95
|
+
clear(): void;
|
|
96
|
+
/**
|
|
97
|
+
* The function checks if the size of an object is equal to zero and returns a boolean value.
|
|
98
|
+
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
|
99
|
+
*/
|
|
100
|
+
isEmpty(): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* The `add` function inserts a new node with a given ID and value into a binary tree, updating the count if the node
|
|
103
|
+
* already exists.
|
|
104
|
+
* @param {BinaryTreeNodeId} id - The id parameter is the identifier of the binary tree node. It is used to uniquely
|
|
105
|
+
* identify each node in the binary tree.
|
|
106
|
+
* @param {N} val - The value to be inserted into the binary tree.
|
|
107
|
+
* @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
|
|
108
|
+
* value should be inserted into the binary tree. If not provided, it defaults to 1.
|
|
109
|
+
* @returns The function `add` returns a `N` object if a new node is inserted, or `null` if no new node
|
|
110
|
+
* is inserted, or `undefined` if the insertion fails.
|
|
111
|
+
*/
|
|
112
|
+
add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* The function adds a new node to a binary tree as the left or right child of a given parent node.
|
|
115
|
+
* @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
|
|
116
|
+
* either a node object (`N`) or `null`.
|
|
117
|
+
* @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
|
|
118
|
+
* child.
|
|
119
|
+
* @returns either the left or right child node that was added to the parent node. It can also return `null` or
|
|
120
|
+
* `undefined` in certain cases.
|
|
121
|
+
*/
|
|
122
|
+
addTo(newNode: N | null, parent: N): N | null | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* The `addMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
|
|
125
|
+
* null/undefined values.
|
|
126
|
+
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
|
|
127
|
+
* array of `N` objects.
|
|
128
|
+
* @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
|
|
129
|
+
*/
|
|
130
|
+
addMany(data: N[] | Array<N['val']>): (N | null | undefined)[];
|
|
131
|
+
/**
|
|
132
|
+
* The `fill` function clears the current data and inserts new data, returning a boolean indicating if the insertion
|
|
133
|
+
* was successful.
|
|
134
|
+
* @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
|
|
135
|
+
* array of `N` objects.
|
|
136
|
+
* @returns The method is returning a boolean value.
|
|
137
|
+
*/
|
|
138
|
+
fill(data: N[] | Array<N['val']>): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* The function removes a node from a binary tree and returns information about the deleted node.
|
|
141
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to remove.
|
|
142
|
+
* It is of type `BinaryTreeNodeId`.
|
|
143
|
+
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
|
|
144
|
+
* whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
|
|
145
|
+
* not be decremented and the overall count of the binary tree will not be updated. If `
|
|
146
|
+
* @returns An array of objects is being returned. Each object in the array has two properties: "deleted" and
|
|
147
|
+
* "needBalanced". The "deleted" property contains the deleted node or undefined if no node was deleted. The
|
|
148
|
+
* "needBalanced" property is always null.
|
|
149
|
+
*/
|
|
150
|
+
remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
151
|
+
/**
|
|
152
|
+
* The function calculates the depth of a binary tree node by traversing its parent nodes.
|
|
153
|
+
* @param node - N - This is the node for which we want to calculate the depth. It is a generic type,
|
|
154
|
+
* meaning it can represent any type of data that we want to store in the node.
|
|
155
|
+
* @returns The depth of the given binary tree node.
|
|
156
|
+
*/
|
|
157
|
+
getDepth(node: N): number;
|
|
158
|
+
/**
|
|
159
|
+
* The `getHeight` function calculates the maximum height of a binary tree using either a recursive or iterative
|
|
160
|
+
* approach.
|
|
161
|
+
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
|
|
162
|
+
* `N | null`. It represents the starting node from which to calculate the height of the binary tree.
|
|
163
|
+
* If no value is provided for `beginRoot`, the function will use the `root` property of the class instance as
|
|
164
|
+
* @returns the height of the binary tree.
|
|
165
|
+
*/
|
|
166
|
+
getHeight(beginRoot?: N | null): number;
|
|
167
|
+
/**
|
|
168
|
+
* The `getMinHeight` function calculates the minimum 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 minimum height of the binary
|
|
172
|
+
* tree. If no value is provided for `beginRoot`, the function will use the root node of the binary tree.
|
|
173
|
+
* @returns The function `getMinHeight` returns the minimum height of the binary tree.
|
|
174
|
+
*/
|
|
175
|
+
getMinHeight(beginRoot?: N | null): number;
|
|
176
|
+
/**
|
|
177
|
+
* The function checks if a binary tree is balanced by comparing the minimum height and the maximum height of the tree.
|
|
178
|
+
* @param {N | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
|
|
179
|
+
* of type `N | null`, which means it can either be a `BinaryTreeNode` object or `null`.
|
|
180
|
+
* @returns The method is returning a boolean value.
|
|
181
|
+
*/
|
|
182
|
+
isBalanced(beginRoot?: N | null): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* The function `getNodes` returns an array of binary tree nodes that match a given property value, with options for
|
|
185
|
+
* searching recursively or iteratively.
|
|
186
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
187
|
+
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
188
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
189
|
+
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
|
|
190
|
+
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
191
|
+
* return only one node that matches the `nodeProperty` or `propertyName` criteria. If `onlyOne` is set to `true`, the
|
|
192
|
+
* function will stop traversing the tree and return the first matching node. If `
|
|
193
|
+
* @returns The function `getNodes` returns an array of `N | null | undefined` objects.
|
|
194
|
+
*/
|
|
195
|
+
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
196
|
+
/**
|
|
197
|
+
* The function checks if a binary tree node has a specific property or if any node in the tree has a specific
|
|
198
|
+
* property.
|
|
199
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
200
|
+
* generic type `N`. It represents the property of a binary tree node that you want to check.
|
|
201
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
202
|
+
* specifies the name of the property to check for in the nodes.
|
|
203
|
+
* @returns a boolean value.
|
|
204
|
+
*/
|
|
205
|
+
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
206
|
+
/**
|
|
207
|
+
* The function returns the first binary tree node that matches the given property name and value, or null if no match
|
|
208
|
+
* is found.
|
|
209
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
210
|
+
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
211
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
212
|
+
* specifies the property of the binary tree node to search for. If not provided, it defaults to `'id'`.
|
|
213
|
+
* @returns a BinaryTreeNode object or null.
|
|
214
|
+
*/
|
|
215
|
+
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
216
|
+
/**
|
|
217
|
+
* The function getPathToRoot returns an array of BinaryTreeNode objects representing the path from a given node to the
|
|
218
|
+
* root of a binary tree.
|
|
219
|
+
* @param node - The `node` parameter is a BinaryTreeNode object.
|
|
220
|
+
* @returns The function `getPathToRoot` returns an array of `N` objects, representing the path from
|
|
221
|
+
* the given `node` to the root of the binary tree.
|
|
222
|
+
*/
|
|
223
|
+
getPathToRoot(node: N): N[];
|
|
224
|
+
getLeftMost(): N | null;
|
|
225
|
+
getLeftMost(node: N): N;
|
|
226
|
+
getRightMost(): N | null;
|
|
227
|
+
getRightMost(node: N): N;
|
|
228
|
+
/**
|
|
229
|
+
* The function `isBSTByRooted` checks if a binary tree is a binary search tree (BST) by rooted traversal.
|
|
230
|
+
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
|
|
231
|
+
* @returns a boolean value.
|
|
232
|
+
*/
|
|
233
|
+
isBSTByRooted(node: N | null): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* The function checks if a binary tree is a binary search tree.
|
|
236
|
+
* @param {N | null} [node] - The `node` parameter is of type `N` or `null`. It represents the root node of a binary
|
|
237
|
+
* search tree (BST).
|
|
238
|
+
* @returns a boolean value.
|
|
239
|
+
*/
|
|
240
|
+
isBST(node?: N | null): boolean;
|
|
241
|
+
/**
|
|
242
|
+
* The function calculates the size and count of a subtree in a binary tree using either recursive or iterative
|
|
243
|
+
* traversal.
|
|
244
|
+
* @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
|
|
245
|
+
* tree.
|
|
246
|
+
* @returns The function `getSubTreeSizeAndCount` returns an array `[number, number]`. The first element of the array
|
|
247
|
+
* represents the size of the subtree, and the second element represents the count of the nodes in the subtree.
|
|
248
|
+
*/
|
|
249
|
+
getSubTreeSizeAndCount(subTreeRoot: N | null | undefined): [number, number];
|
|
250
|
+
/**
|
|
251
|
+
* The function `subTreeSum` calculates the sum of a specified property in a binary tree, either recursively or
|
|
252
|
+
* iteratively.
|
|
253
|
+
* @param subTreeRoot - The subTreeRoot parameter is the root node of the subtree for which you want to calculate the
|
|
254
|
+
* sum.
|
|
255
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
256
|
+
* specifies the property of the `BinaryTreeNode` object to use for calculating the sum. If `propertyName` is not
|
|
257
|
+
* provided, it defaults to `'val'`.
|
|
258
|
+
* @returns a number, which is the sum of the values of the nodes in the subtree rooted at `subTreeRoot`.
|
|
259
|
+
*/
|
|
260
|
+
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
|
261
|
+
/**
|
|
262
|
+
* The function `subTreeAdd` adds a specified delta value to a property of each node in a binary tree.
|
|
263
|
+
* @param subTreeRoot - The `subTreeRoot` parameter is the root node of the subtree where the values will be modified.
|
|
264
|
+
* @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
|
|
265
|
+
* each node in the subtree should be increased or decreased.
|
|
266
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
267
|
+
* specifies the property of the `BinaryTreeNode` that should be modified. It defaults to `'id'` if not provided.
|
|
268
|
+
* @returns a boolean value, which is `true`.
|
|
269
|
+
*/
|
|
270
|
+
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
271
|
+
BFS(): BinaryTreeNodeId[];
|
|
272
|
+
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
|
|
273
|
+
BFS(nodeOrPropertyName: 'val'): N['val'][];
|
|
274
|
+
BFS(nodeOrPropertyName: 'node'): N[];
|
|
275
|
+
BFS(nodeOrPropertyName: 'count'): number[];
|
|
276
|
+
DFS(): BinaryTreeNodeId[];
|
|
277
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
278
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
279
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
280
|
+
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
281
|
+
DFSIterative(): BinaryTreeNodeId[];
|
|
282
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
283
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
284
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
285
|
+
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
286
|
+
levelIterative(node: N | null): BinaryTreeNodeId[];
|
|
287
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
288
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
|
289
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
|
290
|
+
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
|
291
|
+
listLevels(node: N | null): BinaryTreeNodeId[][];
|
|
292
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
|
|
293
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
|
294
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
|
295
|
+
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
|
296
|
+
/**
|
|
297
|
+
* The function returns the predecessor of a given node in a binary tree.
|
|
298
|
+
* @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
|
|
299
|
+
* @returns the predecessor of the given node in a binary tree.
|
|
300
|
+
*/
|
|
301
|
+
getPredecessor(node: N): N;
|
|
302
|
+
morris(): BinaryTreeNodeId[];
|
|
303
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
304
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
305
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
306
|
+
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
307
|
+
protected _setLoopType(value: LoopType): void;
|
|
308
|
+
protected _setVisitedId(value: BinaryTreeNodeId[]): void;
|
|
309
|
+
protected _setVisitedVal(value: Array<N>): void;
|
|
310
|
+
protected _setVisitedNode(value: N[]): void;
|
|
311
|
+
protected setVisitedCount(value: number[]): void;
|
|
312
|
+
protected _setVisitedLeftSum(value: number[]): void;
|
|
313
|
+
protected _setAutoIncrementId(value: boolean): void;
|
|
314
|
+
protected _setMaxId(value: number): void;
|
|
315
|
+
protected _setIsDuplicatedVal(value: boolean): void;
|
|
316
|
+
protected _setRoot(v: N | null): void;
|
|
317
|
+
protected _setSize(v: number): void;
|
|
318
|
+
protected _setCount(v: number): void;
|
|
319
|
+
/**
|
|
320
|
+
* The function resets the values of several arrays used for tracking visited nodes and their properties.
|
|
321
|
+
*/
|
|
322
|
+
protected _resetResults(): void;
|
|
323
|
+
/**
|
|
324
|
+
* The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
|
|
325
|
+
* a result array.
|
|
326
|
+
* @param cur - The current binary tree node that is being checked.
|
|
327
|
+
* @param {(N | null | undefined)[]} result - An array that stores the matching nodes found during the
|
|
328
|
+
* traversal.
|
|
329
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
|
|
330
|
+
* the binary tree nodes. It can be either the `id`, `count`, or `val` property of the node.
|
|
331
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
332
|
+
* specifies the property of the `BinaryTreeNode` object that you want to compare with the `nodeProperty` value. It can
|
|
333
|
+
* be one of the following values: 'id', 'count', or 'val'. If no `propertyName` is provided,
|
|
334
|
+
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
335
|
+
* stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
|
|
336
|
+
* `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
|
|
337
|
+
* @returns a boolean value indicating whether or not a node was pushed into the result array.
|
|
338
|
+
*/
|
|
339
|
+
protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
|
|
340
|
+
/**
|
|
341
|
+
* The function `_accumulatedByPropertyName` pushes a property value of a binary tree node into an array based on the
|
|
342
|
+
* provided property name or a default property name.
|
|
343
|
+
* @param node - The `node` parameter is of type `N`, which represents a node in a binary tree.
|
|
344
|
+
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
|
|
345
|
+
* can be either a string representing a property name or a reference to a node object. If it is a string, it specifies
|
|
346
|
+
* the property name of the node that should be accumulated. If it is a node object, it specifies the node itself
|
|
347
|
+
*/
|
|
348
|
+
protected _accumulatedByPropertyName(node: N, nodeOrPropertyName?: NodeOrPropertyName): void;
|
|
349
|
+
/**
|
|
350
|
+
* The function `_getResultByPropertyName` returns different results based on the provided property name or defaulting
|
|
351
|
+
* to 'id'.
|
|
352
|
+
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
|
|
353
|
+
* can accept a value of type `NodeOrPropertyName`.
|
|
354
|
+
* @returns The method returns an object of type `AbstractBinaryTreeNodeProperties<T>`.
|
|
355
|
+
*/
|
|
356
|
+
protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
357
|
+
}
|