data-structure-typed 1.18.7 → 1.19.0
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/README.md +208 -419
- package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +198 -167
- package/dist/data-structures/binary-tree/abstract-binary-tree.js +413 -398
- package/dist/data-structures/binary-tree/avl-tree.d.ts +24 -16
- package/dist/data-structures/binary-tree/avl-tree.js +23 -17
- package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
- package/dist/data-structures/binary-tree/binary-tree.js +12 -27
- package/dist/data-structures/binary-tree/bst.d.ts +66 -90
- package/dist/data-structures/binary-tree/bst.js +85 -163
- package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -17
- package/dist/data-structures/binary-tree/rb-tree.js +5 -17
- package/dist/data-structures/binary-tree/tree-multiset.d.ts +187 -18
- package/dist/data-structures/binary-tree/tree-multiset.js +716 -39
- package/dist/data-structures/graph/abstract-graph.d.ts +112 -52
- package/dist/data-structures/graph/abstract-graph.js +138 -72
- package/dist/data-structures/graph/directed-graph.d.ts +104 -101
- package/dist/data-structures/graph/directed-graph.js +134 -129
- package/dist/data-structures/graph/undirected-graph.d.ts +66 -65
- package/dist/data-structures/graph/undirected-graph.js +107 -106
- package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +12 -18
- package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
- package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
- package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
- package/dist/data-structures/interfaces/bst.d.ts +4 -5
- package/dist/data-structures/interfaces/rb-tree.d.ts +2 -3
- package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
- package/dist/data-structures/tree/tree.d.ts +1 -4
- package/dist/data-structures/tree/tree.js +1 -12
- package/dist/data-structures/types/abstract-binary-tree.d.ts +10 -6
- package/dist/data-structures/types/abstract-binary-tree.js +9 -5
- package/dist/data-structures/types/avl-tree.d.ts +1 -1
- package/dist/data-structures/types/binary-tree.d.ts +1 -1
- package/dist/data-structures/types/bst.d.ts +1 -1
- package/dist/data-structures/types/bst.js +1 -1
- package/dist/data-structures/types/directed-graph.js +1 -1
- package/dist/data-structures/types/helpers.d.ts +1 -8
- package/dist/data-structures/types/rb-tree.d.ts +2 -0
- package/dist/data-structures/types/rb-tree.js +1 -1
- package/dist/data-structures/types/tree-multiset.d.ts +5 -5
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/types/index.d.ts +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/validate-type.d.ts +19 -0
- package/dist/utils/types/validate-type.js +2 -0
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js +0 -62
- package/dist/utils/validate-type.d.ts +45 -0
- package/dist/utils/validate-type.js +58 -0
- package/package.json +5 -2
- package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
- package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
- package/backup/recursive-type/src/assets/logo.png +0 -0
- package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
- package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
- package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
- package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
- package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
- package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
- package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
- package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
- package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
- package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
- package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
- package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
- package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
- package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
- package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
- package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
- package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
- package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
- package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
- package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
- package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
- package/backup/recursive-type/src/data-structures/index.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
- package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
- package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
- package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
- package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
- package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
- package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
- package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
- package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
- package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
- package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
- package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
- package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
- package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
- package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
- package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
- package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
- package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
- package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
- package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
- package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
- package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
- package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
- package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
- package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
- package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
- package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
- package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
- package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
- package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
- package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
- package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
- package/backup/recursive-type/src/index.ts +0 -1
- package/backup/recursive-type/src/utils/index.ts +0 -2
- package/backup/recursive-type/src/utils/types/index.ts +0 -1
- package/backup/recursive-type/src/utils/types/utils.ts +0 -6
- package/backup/recursive-type/src/utils/utils.ts +0 -78
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -92
- package/docs/assets/main.js +0 -58
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1367
- package/docs/classes/AVLTree.html +0 -2451
- package/docs/classes/AVLTreeNode.html +0 -499
- package/docs/classes/AaTree.html +0 -172
- package/docs/classes/AbstractBinaryTree.html +0 -2118
- package/docs/classes/AbstractBinaryTreeNode.html +0 -524
- package/docs/classes/AbstractEdge.html +0 -295
- package/docs/classes/AbstractGraph.html +0 -1043
- package/docs/classes/AbstractVertex.html +0 -258
- package/docs/classes/ArrayDeque.html +0 -439
- package/docs/classes/BST.html +0 -2297
- package/docs/classes/BSTNode.html +0 -503
- package/docs/classes/BTree.html +0 -172
- package/docs/classes/BinaryIndexedTree.html +0 -341
- package/docs/classes/BinaryTree.html +0 -2133
- package/docs/classes/BinaryTreeNode.html +0 -501
- package/docs/classes/Character.html +0 -220
- package/docs/classes/CoordinateMap.html +0 -483
- package/docs/classes/CoordinateSet.html +0 -444
- package/docs/classes/Deque.html +0 -975
- package/docs/classes/DirectedEdge.html +0 -366
- package/docs/classes/DirectedGraph.html +0 -1443
- package/docs/classes/DirectedVertex.html +0 -254
- package/docs/classes/DoublyLinkedList.html +0 -968
- package/docs/classes/DoublyLinkedListNode.html +0 -297
- package/docs/classes/HashTable.html +0 -172
- package/docs/classes/Heap.html +0 -423
- package/docs/classes/HeapItem.html +0 -255
- package/docs/classes/Matrix2D.html +0 -502
- package/docs/classes/MatrixNTI2D.html +0 -240
- package/docs/classes/MaxHeap.html +0 -436
- package/docs/classes/MaxPriorityQueue.html +0 -836
- package/docs/classes/MinHeap.html +0 -437
- package/docs/classes/MinPriorityQueue.html +0 -838
- package/docs/classes/Navigator.html +0 -313
- package/docs/classes/ObjectDeque.html +0 -455
- package/docs/classes/Pair.html +0 -172
- package/docs/classes/PriorityQueue.html +0 -760
- package/docs/classes/Queue.html +0 -392
- package/docs/classes/RBTree.html +0 -2388
- package/docs/classes/RBTreeNode.html +0 -516
- package/docs/classes/SegmentTree.html +0 -434
- package/docs/classes/SegmentTreeNode.html +0 -357
- package/docs/classes/SinglyLinkedList.html +0 -788
- package/docs/classes/SinglyLinkedListNode.html +0 -270
- package/docs/classes/SkipLinkedList.html +0 -172
- package/docs/classes/SplayTree.html +0 -172
- package/docs/classes/Stack.html +0 -368
- package/docs/classes/TreeMap.html +0 -172
- package/docs/classes/TreeMultiSet.html +0 -2297
- package/docs/classes/TreeMultiSetNode.html +0 -499
- package/docs/classes/TreeNode.html +0 -343
- package/docs/classes/TreeSet.html +0 -172
- package/docs/classes/Trie.html +0 -372
- package/docs/classes/TrieNode.html +0 -280
- package/docs/classes/TwoThreeTree.html +0 -172
- package/docs/classes/UndirectedEdge.html +0 -337
- package/docs/classes/UndirectedGraph.html +0 -1210
- package/docs/classes/UndirectedVertex.html +0 -254
- package/docs/classes/Vector2D.html +0 -805
- package/docs/enums/CP.html +0 -181
- package/docs/enums/FamilyPosition.html +0 -181
- package/docs/enums/LoopType.html +0 -182
- package/docs/enums/RBColor.html +0 -174
- package/docs/enums/TopologicalProperty.html +0 -181
- package/docs/index.html +0 -645
- package/docs/interfaces/IAVLTree.html +0 -1378
- package/docs/interfaces/IAVLTreeNode.html +0 -405
- package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
- package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
- package/docs/interfaces/IAbstractGraph.html +0 -433
- package/docs/interfaces/IBST.html +0 -1271
- package/docs/interfaces/IBSTNode.html +0 -408
- package/docs/interfaces/IDirectedGraph.html +0 -572
- package/docs/interfaces/IUNDirectedGraph.html +0 -465
- package/docs/modules.html +0 -262
- package/docs/types/AVLTreeOptions.html +0 -150
- package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
- package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
- package/docs/types/AbstractBinaryTreeOptions.html +0 -156
- package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
- package/docs/types/BSTComparator.html +0 -162
- package/docs/types/BSTOptions.html +0 -152
- package/docs/types/BinaryTreeDeletedResult.html +0 -159
- package/docs/types/BinaryTreeNodeId.html +0 -147
- package/docs/types/BinaryTreeNodePropertyName.html +0 -147
- package/docs/types/BinaryTreeOptions.html +0 -150
- package/docs/types/DFSOrderPattern.html +0 -147
- package/docs/types/DijkstraResult.html +0 -167
- package/docs/types/Direction.html +0 -147
- package/docs/types/EdgeId.html +0 -147
- package/docs/types/HeapOptions.html +0 -168
- package/docs/types/IdObject.html +0 -157
- package/docs/types/KeyValObject.html +0 -152
- package/docs/types/NavigatorParams.html +0 -181
- package/docs/types/NodeOrPropertyName.html +0 -147
- package/docs/types/PriorityQueueComparator.html +0 -167
- package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
- package/docs/types/PriorityQueueOptions.html +0 -161
- package/docs/types/RBTreeOptions.html +0 -150
- package/docs/types/RecursiveAVLTreeNode.html +0 -152
- package/docs/types/RecursiveBSTNode.html +0 -152
- package/docs/types/RecursiveBinaryTreeNode.html +0 -152
- package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
- package/docs/types/SegmentTreeNodeVal.html +0 -147
- package/docs/types/TopologicalStatus.html +0 -147
- package/docs/types/TreeMultiSetOptions.html +0 -152
- package/docs/types/Turning.html +0 -147
- package/docs/types/VertexId.html +0 -147
- package/notes/bst.test.ts +0 -181
- package/notes/note.md +0 -34
|
@@ -5,67 +5,61 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import type {
|
|
8
|
+
import type { AbstractBinaryTreeNodeNested, AbstractBinaryTreeNodeProperties, BinaryTreeDeletedResult, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName } from '../types';
|
|
9
9
|
import { AbstractBinaryTreeOptions, FamilyPosition, LoopType } from '../types';
|
|
10
10
|
import { IAbstractBinaryTree, IAbstractBinaryTreeNode } from '../interfaces';
|
|
11
|
-
export declare abstract class AbstractBinaryTreeNode<T =
|
|
11
|
+
export declare abstract class AbstractBinaryTreeNode<T = any, NEIGHBOR extends AbstractBinaryTreeNode<T, NEIGHBOR> = AbstractBinaryTreeNodeNested<T>> implements IAbstractBinaryTreeNode<T, NEIGHBOR> {
|
|
12
12
|
/**
|
|
13
|
-
* The constructor function initializes a BinaryTreeNode object with an id
|
|
13
|
+
* The constructor function initializes a BinaryTreeNode object with an id and an optional value.
|
|
14
14
|
* @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
|
|
15
|
-
*
|
|
16
|
-
* @param {T} [val] - The
|
|
17
|
-
* tree node. If no value is provided, it will be
|
|
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.
|
|
15
|
+
* of the binary tree node. It is used to distinguish one node from another in the binary tree.
|
|
16
|
+
* @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value that will be
|
|
17
|
+
* stored in the binary tree node. If no value is provided, it will be set to undefined.
|
|
20
18
|
*/
|
|
21
|
-
constructor(id: BinaryTreeNodeId, val?: T
|
|
19
|
+
constructor(id: BinaryTreeNodeId, val?: T);
|
|
22
20
|
private _id;
|
|
23
21
|
get id(): BinaryTreeNodeId;
|
|
24
22
|
set id(v: BinaryTreeNodeId);
|
|
25
23
|
private _val;
|
|
26
24
|
get val(): T | undefined;
|
|
27
25
|
set val(value: T | undefined);
|
|
28
|
-
private _left
|
|
29
|
-
get left():
|
|
30
|
-
set left(v:
|
|
31
|
-
private _right
|
|
32
|
-
get right():
|
|
33
|
-
set right(v:
|
|
26
|
+
private _left;
|
|
27
|
+
get left(): NEIGHBOR | null | undefined;
|
|
28
|
+
set left(v: NEIGHBOR | null | undefined);
|
|
29
|
+
private _right;
|
|
30
|
+
get right(): NEIGHBOR | null | undefined;
|
|
31
|
+
set right(v: NEIGHBOR | null | undefined);
|
|
34
32
|
private _parent;
|
|
35
|
-
get parent():
|
|
36
|
-
set parent(v:
|
|
37
|
-
private _familyPosition;
|
|
38
|
-
get familyPosition(): FamilyPosition;
|
|
39
|
-
set familyPosition(v: FamilyPosition);
|
|
40
|
-
private _count;
|
|
41
|
-
get count(): number;
|
|
42
|
-
set count(v: number);
|
|
33
|
+
get parent(): NEIGHBOR | null | undefined;
|
|
34
|
+
set parent(v: NEIGHBOR | null | undefined);
|
|
43
35
|
private _height;
|
|
44
36
|
get height(): number;
|
|
45
37
|
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
38
|
/**
|
|
54
|
-
* The
|
|
55
|
-
* @returns
|
|
56
|
-
* `count` values as the current instance.
|
|
39
|
+
* The function determines the position of a node in a family tree structure.
|
|
40
|
+
* @returns a value of type `FamilyPosition`.
|
|
57
41
|
*/
|
|
58
|
-
|
|
42
|
+
get familyPosition(): FamilyPosition;
|
|
59
43
|
}
|
|
60
|
-
export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N> = AbstractBinaryTreeNode
|
|
44
|
+
export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNode<N['val'], N> = AbstractBinaryTreeNode> implements IAbstractBinaryTree<N> {
|
|
61
45
|
/**
|
|
62
46
|
* The protected constructor initializes the options for an abstract binary tree.
|
|
63
47
|
* @param {AbstractBinaryTreeOptions} [options] - An optional object that contains configuration options for the binary
|
|
64
48
|
* tree.
|
|
65
49
|
*/
|
|
66
50
|
protected constructor(options?: AbstractBinaryTreeOptions);
|
|
51
|
+
private _root;
|
|
52
|
+
get root(): N | null;
|
|
53
|
+
private _size;
|
|
54
|
+
get size(): number;
|
|
67
55
|
private _loopType;
|
|
68
56
|
get loopType(): LoopType;
|
|
57
|
+
private _autoIncrementId;
|
|
58
|
+
get autoIncrementId(): boolean;
|
|
59
|
+
private _maxId;
|
|
60
|
+
get maxId(): number;
|
|
61
|
+
private _isMergeDuplicatedVal;
|
|
62
|
+
get isMergeDuplicatedVal(): boolean;
|
|
69
63
|
private _visitedId;
|
|
70
64
|
get visitedId(): BinaryTreeNodeId[];
|
|
71
65
|
private _visitedVal;
|
|
@@ -76,21 +70,17 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
76
70
|
get visitedCount(): number[];
|
|
77
71
|
private _visitedLeftSum;
|
|
78
72
|
get visitedLeftSum(): number[];
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
get size(): number;
|
|
89
|
-
private _count;
|
|
90
|
-
get count(): number;
|
|
91
|
-
abstract createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
|
|
73
|
+
abstract createNode(id: BinaryTreeNodeId, val?: N['val']): N | null;
|
|
74
|
+
/**
|
|
75
|
+
* The `swapLocation` function swaps the location of two nodes in a binary tree.
|
|
76
|
+
* @param {N} srcNode - The source node that you want to swap with the destination node.
|
|
77
|
+
* @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
|
|
78
|
+
* be swapped to.
|
|
79
|
+
* @returns The `destNode` is being returned.
|
|
80
|
+
*/
|
|
81
|
+
swapLocation(srcNode: N, destNode: N): N;
|
|
92
82
|
/**
|
|
93
|
-
* The clear function resets the
|
|
83
|
+
* The clear() function resets the root, size, and maxId properties to their initial values.
|
|
94
84
|
*/
|
|
95
85
|
clear(): void;
|
|
96
86
|
/**
|
|
@@ -99,126 +89,121 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
99
89
|
*/
|
|
100
90
|
isEmpty(): boolean;
|
|
101
91
|
/**
|
|
102
|
-
* The `add` function
|
|
103
|
-
*
|
|
104
|
-
* @param
|
|
105
|
-
*
|
|
106
|
-
* @param {
|
|
107
|
-
*
|
|
108
|
-
*
|
|
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.
|
|
92
|
+
* The `add` function adds a new node to a binary tree, updating the value of an existing node if it already exists.
|
|
93
|
+
* @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
|
|
94
|
+
* @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. If no value is
|
|
95
|
+
* provided, the default value will be the same as the `id` parameter.
|
|
96
|
+
* @param {number} [count] - The `count` parameter is an optional number that represents the number of times the value
|
|
97
|
+
* should be added to the binary tree. If not provided, the default value is `undefined`.
|
|
98
|
+
* @returns The function `add` returns either a `BinaryTreeNode` object (`N`), `null`, or `undefined`.
|
|
111
99
|
*/
|
|
112
100
|
add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null | undefined;
|
|
113
101
|
/**
|
|
114
|
-
* The function adds a new node to
|
|
102
|
+
* The function adds a new node to the left or right child of a parent node, updating the size of the tree if
|
|
103
|
+
* necessary.
|
|
115
104
|
* @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
|
|
116
105
|
* either a node object (`N`) or `null`.
|
|
117
106
|
* @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
|
|
118
107
|
* child.
|
|
119
|
-
* @returns either the left
|
|
120
|
-
* `undefined` in certain cases.
|
|
108
|
+
* @returns either the left child node, the right child node, or undefined.
|
|
121
109
|
*/
|
|
122
110
|
addTo(newNode: N | null, parent: N): N | null | undefined;
|
|
123
111
|
/**
|
|
124
|
-
* The `addMany` function
|
|
112
|
+
* The `addMany` function adds multiple nodes to a binary tree and returns an array of the inserted nodes or
|
|
125
113
|
* null/undefined values.
|
|
126
|
-
* @param {N[] | N[]} data - The `data` parameter can be either an array of
|
|
127
|
-
*
|
|
128
|
-
* @returns The function `addMany` returns an array of `N
|
|
114
|
+
* @param {N[] | Array<N['val']>} data - The `data` parameter can be either an array of `N` objects or an array of
|
|
115
|
+
* `N['val']` values.
|
|
116
|
+
* @returns The function `addMany` returns an array of values of type `N | null | undefined`.
|
|
129
117
|
*/
|
|
130
118
|
addMany(data: N[] | Array<N['val']>): (N | null | undefined)[];
|
|
131
119
|
/**
|
|
132
|
-
* The `fill` function clears the current data and
|
|
133
|
-
*
|
|
134
|
-
* @param {N[] | N[]} data - The `data` parameter can be either an array of
|
|
135
|
-
* array
|
|
136
|
-
* @returns
|
|
120
|
+
* The `fill` function clears the current data and adds new data, returning a boolean indicating if the operation was
|
|
121
|
+
* successful.
|
|
122
|
+
* @param {N[] | Array<N['val']>} data - The `data` parameter can be either an array of objects or an array of arrays.
|
|
123
|
+
* Each object or array should have a property called `val`.
|
|
124
|
+
* @returns a boolean value.
|
|
137
125
|
*/
|
|
138
126
|
fill(data: N[] | Array<N['val']>): boolean;
|
|
139
127
|
/**
|
|
140
|
-
* The function removes a node from a binary tree and returns
|
|
141
|
-
*
|
|
142
|
-
*
|
|
128
|
+
* The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
|
|
129
|
+
* node that needs to be balanced.
|
|
130
|
+
* @param {N | BinaryTreeNodeId} nodeOrId - The `nodeOrId` parameter can be either a node object (`N`) or a binary tree
|
|
131
|
+
* node ID (`BinaryTreeNodeId`).
|
|
143
132
|
* @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
|
|
144
|
-
* whether to ignore the count of the
|
|
145
|
-
*
|
|
146
|
-
* @returns
|
|
147
|
-
* "needBalanced". The "deleted" property contains the deleted node or undefined if no node was deleted. The
|
|
148
|
-
* "needBalanced" property is always null.
|
|
133
|
+
* whether to ignore the count of the nodes in the binary tree. If `ignoreCount` is set to `true`, the count of the
|
|
134
|
+
* nodes in the binary tree will not be updated after removing a node. If `ignoreCount`
|
|
135
|
+
* @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
|
|
149
136
|
*/
|
|
150
|
-
remove(
|
|
137
|
+
remove(nodeOrId: N | BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeletedResult<N>[];
|
|
151
138
|
/**
|
|
152
|
-
* The function calculates the depth of a
|
|
153
|
-
* @param
|
|
154
|
-
*
|
|
155
|
-
* @returns The depth of the given binary tree node.
|
|
139
|
+
* The function calculates the depth of a node in a binary tree.
|
|
140
|
+
* @param {N | BinaryTreeNodeId | null} beginRoot - The `beginRoot` parameter can be one of the following:
|
|
141
|
+
* @returns the depth of the given node or binary tree.
|
|
156
142
|
*/
|
|
157
|
-
getDepth(
|
|
143
|
+
getDepth(beginRoot: N | BinaryTreeNodeId | null): number;
|
|
158
144
|
/**
|
|
159
|
-
* The `getHeight` function calculates the maximum height of a binary tree
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* If no value is provided for `beginRoot`, the function will use the `root` property of the class instance as
|
|
145
|
+
* The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
|
|
146
|
+
* @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
|
|
147
|
+
* generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
|
|
148
|
+
* node), or `null`.
|
|
164
149
|
* @returns the height of the binary tree.
|
|
165
150
|
*/
|
|
166
|
-
getHeight(beginRoot?: N | null): number;
|
|
151
|
+
getHeight(beginRoot?: N | BinaryTreeNodeId | null): number;
|
|
167
152
|
/**
|
|
168
153
|
* The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
|
|
169
154
|
* approach.
|
|
170
|
-
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
|
|
171
|
-
*
|
|
172
|
-
*
|
|
155
|
+
* @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type `N` or `null`. It
|
|
156
|
+
* represents the starting node from which to calculate the minimum height of a binary tree. If no value is provided
|
|
157
|
+
* for `beginRoot`, the `this.root` property is used as the default value.
|
|
173
158
|
* @returns The function `getMinHeight` returns the minimum height of the binary tree.
|
|
174
159
|
*/
|
|
175
160
|
getMinHeight(beginRoot?: N | null): number;
|
|
176
161
|
/**
|
|
177
|
-
* The function checks if a binary tree is balanced by comparing the minimum height and the
|
|
178
|
-
*
|
|
179
|
-
*
|
|
162
|
+
* The function checks if a binary tree is perfectly balanced by comparing the minimum height and the height of the
|
|
163
|
+
* tree.
|
|
164
|
+
* @param {N | null} [beginRoot] - The parameter `beginRoot` is of type `N` or `null`. It represents the root node of a
|
|
165
|
+
* tree or null if the tree is empty.
|
|
180
166
|
* @returns The method is returning a boolean value.
|
|
181
167
|
*/
|
|
182
|
-
|
|
168
|
+
isPerfectlyBalanced(beginRoot?: N | null): boolean;
|
|
183
169
|
/**
|
|
184
|
-
* The function `getNodes` returns an array of
|
|
185
|
-
* searching recursively or iteratively.
|
|
170
|
+
* The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
|
|
186
171
|
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
|
|
187
172
|
* generic type `N`. It represents the property of the binary tree node that you want to search for.
|
|
188
173
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
189
174
|
* specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
|
|
190
175
|
* @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
|
|
192
|
-
* function will stop traversing the tree and return the first matching node. If `
|
|
193
|
-
* @returns
|
|
176
|
+
* return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the
|
|
177
|
+
* function will stop traversing the tree and return the first matching node. If `only
|
|
178
|
+
* @returns an array of nodes (type N).
|
|
194
179
|
*/
|
|
195
180
|
getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): N[];
|
|
196
181
|
/**
|
|
197
|
-
* The function checks if a binary tree node has a specific property
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* generic type `N`. It represents the property of a binary tree node that you want to check.
|
|
182
|
+
* The function checks if a binary tree node has a specific property.
|
|
183
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
|
|
184
|
+
* It represents the property of the binary tree node that you want to check.
|
|
201
185
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
202
|
-
* specifies the name of the property to
|
|
186
|
+
* specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.
|
|
203
187
|
* @returns a boolean value.
|
|
204
188
|
*/
|
|
205
189
|
has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
206
190
|
/**
|
|
207
|
-
* The function returns the first
|
|
208
|
-
*
|
|
209
|
-
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or
|
|
210
|
-
*
|
|
191
|
+
* The function returns the first node that matches the given property name and value, or null if no matching node is
|
|
192
|
+
* found.
|
|
193
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
|
|
194
|
+
* It represents the property of the binary tree node that you want to search for.
|
|
211
195
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
212
|
-
* specifies the property
|
|
213
|
-
*
|
|
196
|
+
* specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
|
|
197
|
+
* default value is set to `'id'`.
|
|
198
|
+
* @returns either the value of the specified property of the node, or the node itself if no property name is provided.
|
|
199
|
+
* If no matching node is found, it returns null.
|
|
214
200
|
*/
|
|
215
201
|
get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
|
|
216
202
|
/**
|
|
217
|
-
* The function getPathToRoot returns an array of
|
|
218
|
-
* root
|
|
219
|
-
* @param node - The `node`
|
|
220
|
-
* @returns The function `getPathToRoot` returns an array of `N`
|
|
221
|
-
* the given `node` to the root of the binary tree.
|
|
203
|
+
* The function getPathToRoot takes a node and returns an array of nodes representing the path from the given node to
|
|
204
|
+
* the root node.
|
|
205
|
+
* @param {N} node - The parameter `node` represents a node in a tree data structure.
|
|
206
|
+
* @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
|
|
222
207
|
*/
|
|
223
208
|
getPathToRoot(node: N): N[];
|
|
224
209
|
getLeftMost(): N | null;
|
|
@@ -226,7 +211,7 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
226
211
|
getRightMost(): N | null;
|
|
227
212
|
getRightMost(node: N): N;
|
|
228
213
|
/**
|
|
229
|
-
* The function
|
|
214
|
+
* The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
|
|
230
215
|
* @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
|
|
231
216
|
* @returns a boolean value.
|
|
232
217
|
*/
|
|
@@ -239,60 +224,53 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
239
224
|
*/
|
|
240
225
|
isBST(node?: N | null): boolean;
|
|
241
226
|
/**
|
|
242
|
-
* The function calculates the size
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
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.
|
|
227
|
+
* The function calculates the size of a subtree by traversing it either recursively or iteratively.
|
|
228
|
+
* @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
|
|
229
|
+
* binary tree.
|
|
230
|
+
* @returns the size of the subtree rooted at `subTreeRoot`.
|
|
248
231
|
*/
|
|
249
|
-
|
|
232
|
+
getSubTreeSize(subTreeRoot: N | null | undefined): number;
|
|
250
233
|
/**
|
|
251
|
-
* The function `subTreeSum` calculates the sum of a specified property in a binary tree
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
* @returns a number, which is the sum of the values of the nodes in the subtree rooted at `subTreeRoot`.
|
|
234
|
+
* The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
|
|
235
|
+
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
|
|
236
|
+
* tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
|
|
237
|
+
* @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
|
|
238
|
+
* property of the binary tree node to use for calculating the sum. It can be either 'id' or 'val'. If propertyName is
|
|
239
|
+
* not provided, it defaults to 'id'.
|
|
240
|
+
* @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
|
|
259
241
|
*/
|
|
260
|
-
subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
|
|
242
|
+
subTreeSum(subTreeRoot: N | BinaryTreeNodeId | null, propertyName?: BinaryTreeNodePropertyName): number;
|
|
261
243
|
/**
|
|
262
|
-
* The function `subTreeAdd` adds a
|
|
263
|
-
* @param subTreeRoot - The `subTreeRoot` parameter
|
|
244
|
+
* The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
|
|
245
|
+
* @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
|
|
246
|
+
* tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
|
|
264
247
|
* @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
|
|
248
|
+
* each node in the subtree should be incremented.
|
|
266
249
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
267
|
-
* specifies the property of the
|
|
268
|
-
* @returns a boolean value
|
|
250
|
+
* specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.
|
|
251
|
+
* @returns a boolean value.
|
|
269
252
|
*/
|
|
270
|
-
subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
253
|
+
subTreeAdd(subTreeRoot: N | BinaryTreeNodeId | null, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
|
|
271
254
|
BFS(): BinaryTreeNodeId[];
|
|
272
255
|
BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
|
|
273
256
|
BFS(nodeOrPropertyName: 'val'): N['val'][];
|
|
274
257
|
BFS(nodeOrPropertyName: 'node'): N[];
|
|
275
|
-
BFS(nodeOrPropertyName: 'count'): number[];
|
|
276
258
|
DFS(): BinaryTreeNodeId[];
|
|
277
259
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
278
260
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
279
261
|
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
280
|
-
DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
281
262
|
DFSIterative(): BinaryTreeNodeId[];
|
|
282
263
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
283
264
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
284
265
|
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
285
|
-
DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
|
|
286
266
|
levelIterative(node: N | null): BinaryTreeNodeId[];
|
|
287
267
|
levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
288
268
|
levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
|
|
289
269
|
levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
|
|
290
|
-
levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
|
|
291
270
|
listLevels(node: N | null): BinaryTreeNodeId[][];
|
|
292
271
|
listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
|
|
293
272
|
listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
|
|
294
273
|
listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
|
|
295
|
-
listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
|
|
296
274
|
/**
|
|
297
275
|
* The function returns the predecessor of a given node in a binary tree.
|
|
298
276
|
* @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
|
|
@@ -302,56 +280,109 @@ export declare abstract class AbstractBinaryTree<N extends AbstractBinaryTreeNod
|
|
|
302
280
|
morris(): BinaryTreeNodeId[];
|
|
303
281
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
|
|
304
282
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
|
|
283
|
+
/**
|
|
284
|
+
* Time complexity is O(n)
|
|
285
|
+
* Space complexity of Iterative DFS equals to recursive DFS which is O(n) because of the stack
|
|
286
|
+
*/
|
|
305
287
|
morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
|
|
306
|
-
|
|
288
|
+
/**
|
|
289
|
+
* The function sets the loop type for a protected variable.
|
|
290
|
+
* @param {LoopType} value - The value parameter is of type LoopType.
|
|
291
|
+
*/
|
|
307
292
|
protected _setLoopType(value: LoopType): void;
|
|
293
|
+
/**
|
|
294
|
+
* The function sets the value of the `_visitedId` property in a protected manner.
|
|
295
|
+
* @param {BinaryTreeNodeId[]} value - value is an array of BinaryTreeNodeId values.
|
|
296
|
+
*/
|
|
308
297
|
protected _setVisitedId(value: BinaryTreeNodeId[]): void;
|
|
298
|
+
/**
|
|
299
|
+
* The function sets the value of the "_visitedVal" property to the given array.
|
|
300
|
+
* @param value - An array of type N.
|
|
301
|
+
*/
|
|
309
302
|
protected _setVisitedVal(value: Array<N>): void;
|
|
303
|
+
/**
|
|
304
|
+
* The function sets the value of the _visitedNode property.
|
|
305
|
+
* @param {N[]} value - N[] is an array of elements of type N.
|
|
306
|
+
*/
|
|
310
307
|
protected _setVisitedNode(value: N[]): void;
|
|
308
|
+
/**
|
|
309
|
+
* The function sets the value of the visitedCount property.
|
|
310
|
+
* @param {number[]} value - The value parameter is an array of numbers.
|
|
311
|
+
*/
|
|
311
312
|
protected setVisitedCount(value: number[]): void;
|
|
313
|
+
/**
|
|
314
|
+
* The function sets the value of the `_visitedLeftSum` property to the provided array.
|
|
315
|
+
* @param {number[]} value - An array of numbers that represents the visited left sum.
|
|
316
|
+
*/
|
|
312
317
|
protected _setVisitedLeftSum(value: number[]): void;
|
|
318
|
+
/**
|
|
319
|
+
* The function sets the value of the _autoIncrementId property.
|
|
320
|
+
* @param {boolean} value - The value parameter is a boolean that determines whether the id should be automatically
|
|
321
|
+
* incremented or not. If value is true, the id will be automatically incremented. If value is false, the id will not
|
|
322
|
+
* be automatically incremented.
|
|
323
|
+
*/
|
|
313
324
|
protected _setAutoIncrementId(value: boolean): void;
|
|
325
|
+
/**
|
|
326
|
+
* The function sets the maximum ID value.
|
|
327
|
+
* @param {number} value - The value parameter is a number that represents the new maximum ID value.
|
|
328
|
+
*/
|
|
314
329
|
protected _setMaxId(value: number): void;
|
|
330
|
+
/**
|
|
331
|
+
* The function sets the value of a protected property called "_isMergeDuplicatedVal".
|
|
332
|
+
* @param {boolean} value - The value parameter is a boolean value that determines whether the isMergeDuplicatedVal
|
|
333
|
+
* property should be set to true or false.
|
|
334
|
+
*/
|
|
315
335
|
protected _setIsDuplicatedVal(value: boolean): void;
|
|
336
|
+
/**
|
|
337
|
+
* The function sets the root property of an object to a given value, and if the value is not null, it also sets the
|
|
338
|
+
* parent property of the value to undefined.
|
|
339
|
+
* @param {N | null} v - The parameter `v` is of type `N | null`, which means it can either be of type `N` or `null`.
|
|
340
|
+
*/
|
|
316
341
|
protected _setRoot(v: N | null): void;
|
|
342
|
+
/**
|
|
343
|
+
* The function sets the size of a protected variable.
|
|
344
|
+
* @param {number} v - number
|
|
345
|
+
*/
|
|
317
346
|
protected _setSize(v: number): void;
|
|
318
|
-
protected _setCount(v: number): void;
|
|
319
347
|
/**
|
|
320
|
-
* The function resets the values of several arrays used for tracking visited nodes and their
|
|
348
|
+
* The function `_resetResults` resets the values of several arrays used for tracking visited nodes and their
|
|
349
|
+
* properties.
|
|
321
350
|
*/
|
|
322
351
|
protected _resetResults(): void;
|
|
323
352
|
/**
|
|
324
353
|
* The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
|
|
325
354
|
* a result array.
|
|
326
|
-
* @param cur - The current
|
|
327
|
-
* @param {(N | null | undefined)[]} result - An array that stores the matching nodes
|
|
328
|
-
*
|
|
329
|
-
*
|
|
330
|
-
* the binary tree nodes. It can be either the `id`, `count`, or `val` property of the node.
|
|
355
|
+
* @param {N} cur - The current node being processed.
|
|
356
|
+
* @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
|
|
357
|
+
* @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeId` or a `N`
|
|
358
|
+
* type. It represents the property value that we are comparing against in the switch statement.
|
|
331
359
|
* @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
|
|
332
|
-
* specifies the property
|
|
333
|
-
*
|
|
360
|
+
* specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'id'`
|
|
361
|
+
* or `'val'`. If it is not provided or is not equal to `'id'` or `'val'`, the
|
|
334
362
|
* @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
|
|
335
363
|
* stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
|
|
336
364
|
* `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
|
|
337
|
-
* @returns a boolean value indicating whether
|
|
365
|
+
* @returns a boolean value indicating whether only one matching node should be pushed into the result array.
|
|
338
366
|
*/
|
|
339
367
|
protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
|
|
340
368
|
/**
|
|
341
|
-
* The function `_accumulatedByPropertyName`
|
|
342
|
-
*
|
|
343
|
-
* @param
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
* the property name of the node that should be accumulated. If it is a node object, it specifies the node itself
|
|
369
|
+
* The function `_accumulatedByPropertyName` accumulates values from a given node based on the specified property name.
|
|
370
|
+
* @param {N} node - The `node` parameter is of type `N`, which represents a node in a data structure.
|
|
371
|
+
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
|
|
372
|
+
* can be either a string representing a property name or a reference to a `Node` object. If it is a string, it
|
|
373
|
+
* specifies the property name to be used for accumulating values. If it is a `Node` object, it specifies
|
|
347
374
|
*/
|
|
348
375
|
protected _accumulatedByPropertyName(node: N, nodeOrPropertyName?: NodeOrPropertyName): void;
|
|
349
376
|
/**
|
|
350
|
-
* The
|
|
351
|
-
*
|
|
377
|
+
* The time complexity of Morris traversal is O(n), it's may slower than others
|
|
378
|
+
* The space complexity Morris traversal is O(1) because no using stack
|
|
379
|
+
*/
|
|
380
|
+
/**
|
|
381
|
+
* The function `_getResultByPropertyName` returns the corresponding property value based on the given node or property
|
|
382
|
+
* name.
|
|
352
383
|
* @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
|
|
353
|
-
* can accept a
|
|
354
|
-
* @returns The method returns an
|
|
384
|
+
* can accept either a `NodeOrPropertyName` type or be undefined.
|
|
385
|
+
* @returns The method `_getResultByPropertyName` returns an instance of `AbstractBinaryTreeNodeProperties<N>`.
|
|
355
386
|
*/
|
|
356
387
|
protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): AbstractBinaryTreeNodeProperties<N>;
|
|
357
388
|
}
|