data-structure-typed 1.18.0 → 1.18.6

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