data-structure-typed 1.17.4 → 1.18.5

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 (293) 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/avl-tree.d.ts +19 -25
  107. package/dist/data-structures/binary-tree/avl-tree.js +12 -20
  108. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -1
  109. package/dist/data-structures/binary-tree/binary-indexed-tree.js +10 -0
  110. package/dist/data-structures/binary-tree/binary-tree.d.ts +135 -161
  111. package/dist/data-structures/binary-tree/binary-tree.js +192 -164
  112. package/dist/data-structures/binary-tree/bst.d.ts +21 -21
  113. package/dist/data-structures/binary-tree/bst.js +33 -36
  114. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
  115. package/dist/data-structures/binary-tree/rb-tree.js +68 -5
  116. package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -39
  117. package/dist/data-structures/binary-tree/segment-tree.js +34 -47
  118. package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -8
  119. package/dist/data-structures/binary-tree/tree-multiset.js +7 -6
  120. package/dist/data-structures/graph/abstract-graph.d.ts +56 -71
  121. package/dist/data-structures/graph/abstract-graph.js +87 -92
  122. package/dist/data-structures/graph/directed-graph.d.ts +128 -105
  123. package/dist/data-structures/graph/directed-graph.js +161 -121
  124. package/dist/data-structures/graph/undirected-graph.d.ts +81 -62
  125. package/dist/data-structures/graph/undirected-graph.js +99 -78
  126. package/dist/data-structures/hash/coordinate-map.d.ts +1 -5
  127. package/dist/data-structures/hash/coordinate-map.js +3 -9
  128. package/dist/data-structures/hash/coordinate-set.d.ts +2 -6
  129. package/dist/data-structures/hash/coordinate-set.js +3 -9
  130. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  131. package/dist/data-structures/hash/hash-table.js +7 -0
  132. package/dist/data-structures/hash/pair.d.ts +2 -1
  133. package/dist/data-structures/hash/pair.js +7 -0
  134. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  135. package/dist/data-structures/hash/tree-map.js +7 -0
  136. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  137. package/dist/data-structures/hash/tree-set.js +7 -0
  138. package/dist/data-structures/heap/heap.d.ts +0 -14
  139. package/dist/data-structures/heap/heap.js +3 -27
  140. package/dist/data-structures/index.d.ts +1 -0
  141. package/dist/data-structures/index.js +1 -0
  142. package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
  143. package/dist/data-structures/interfaces/abstract-graph.js +2 -0
  144. package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
  145. package/dist/data-structures/interfaces/avl-tree.js +2 -0
  146. package/dist/data-structures/interfaces/binary-tree.d.ts +27 -0
  147. package/dist/data-structures/interfaces/binary-tree.js +2 -0
  148. package/dist/data-structures/interfaces/bst.d.ts +1 -0
  149. package/dist/data-structures/interfaces/bst.js +2 -0
  150. package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
  151. package/dist/data-structures/interfaces/directed-graph.js +2 -0
  152. package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
  153. package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
  154. package/dist/data-structures/interfaces/heap.d.ts +1 -0
  155. package/dist/data-structures/interfaces/heap.js +2 -0
  156. package/dist/data-structures/interfaces/index.d.ts +13 -0
  157. package/dist/data-structures/interfaces/index.js +29 -0
  158. package/dist/data-structures/interfaces/navigator.d.ts +1 -0
  159. package/dist/data-structures/interfaces/navigator.js +2 -0
  160. package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
  161. package/dist/data-structures/interfaces/priority-queue.js +2 -0
  162. package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
  163. package/dist/data-structures/interfaces/segment-tree.js +2 -0
  164. package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
  165. package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
  166. package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
  167. package/dist/data-structures/interfaces/tree-multiset.js +2 -0
  168. package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
  169. package/dist/data-structures/interfaces/undirected-graph.js +2 -0
  170. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -3
  171. package/dist/data-structures/linked-list/doubly-linked-list.js +12 -18
  172. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -2
  173. package/dist/data-structures/linked-list/singly-linked-list.js +12 -15
  174. package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
  175. package/dist/data-structures/priority-queue/priority-queue.js +4 -4
  176. package/dist/data-structures/queue/deque.d.ts +5 -5
  177. package/dist/data-structures/queue/deque.js +6 -6
  178. package/dist/data-structures/queue/queue.d.ts +1 -1
  179. package/dist/data-structures/stack/stack.d.ts +1 -1
  180. package/dist/data-structures/tree/tree.d.ts +12 -4
  181. package/dist/data-structures/tree/tree.js +44 -12
  182. package/dist/data-structures/trie/trie.d.ts +3 -3
  183. package/dist/data-structures/trie/trie.js +10 -10
  184. package/dist/data-structures/types/abstract-graph.d.ts +1 -20
  185. package/dist/data-structures/types/avl-tree.d.ts +5 -4
  186. package/dist/data-structures/types/binary-tree.d.ts +6 -5
  187. package/dist/data-structures/types/bst.d.ts +4 -3
  188. package/dist/data-structures/types/directed-graph.d.ts +5 -9
  189. package/dist/data-structures/types/directed-graph.js +7 -0
  190. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -1
  191. package/dist/data-structures/types/heap.d.ts +2 -2
  192. package/dist/data-structures/types/index.d.ts +0 -1
  193. package/dist/data-structures/types/index.js +0 -1
  194. package/dist/data-structures/types/navigator.d.ts +2 -2
  195. package/dist/data-structures/types/priority-queue.d.ts +2 -2
  196. package/dist/data-structures/types/tree-multiset.d.ts +3 -4
  197. package/docs/assets/search.js +1 -1
  198. package/docs/classes/AVLTree.html +552 -405
  199. package/docs/classes/AVLTreeNode.html +107 -242
  200. package/docs/classes/AaTree.html +18 -13
  201. package/docs/classes/AbstractEdge.html +77 -68
  202. package/docs/classes/AbstractGraph.html +223 -115
  203. package/docs/classes/AbstractVertex.html +71 -45
  204. package/docs/classes/ArrayDeque.html +31 -26
  205. package/docs/classes/BST.html +543 -391
  206. package/docs/classes/BSTNode.html +107 -236
  207. package/docs/classes/BTree.html +18 -13
  208. package/docs/classes/BinaryIndexedTree.html +56 -21
  209. package/docs/classes/BinaryTree.html +564 -355
  210. package/docs/classes/BinaryTreeNode.html +146 -199
  211. package/docs/classes/Character.html +21 -16
  212. package/docs/classes/CoordinateMap.html +49 -52
  213. package/docs/classes/CoordinateSet.html +50 -53
  214. package/docs/classes/Deque.html +51 -68
  215. package/docs/classes/DirectedEdge.html +98 -103
  216. package/docs/classes/DirectedGraph.html +449 -210
  217. package/docs/classes/DirectedVertex.html +63 -52
  218. package/docs/classes/DoublyLinkedList.html +56 -71
  219. package/docs/classes/DoublyLinkedListNode.html +28 -23
  220. package/docs/classes/HashTable.html +155 -0
  221. package/docs/classes/Heap.html +33 -109
  222. package/docs/classes/HeapItem.html +25 -20
  223. package/docs/classes/Matrix2D.html +33 -28
  224. package/docs/classes/MatrixNTI2D.html +21 -16
  225. package/docs/classes/MaxHeap.html +33 -114
  226. package/docs/classes/MaxPriorityQueue.html +71 -61
  227. package/docs/classes/MinHeap.html +33 -114
  228. package/docs/classes/MinPriorityQueue.html +71 -61
  229. package/docs/classes/Navigator.html +28 -23
  230. package/docs/classes/ObjectDeque.html +66 -51
  231. package/docs/classes/{RBTree.html → Pair.html} +25 -20
  232. package/docs/classes/PriorityQueue.html +66 -56
  233. package/docs/classes/Queue.html +33 -28
  234. package/docs/classes/SegmentTree.html +129 -57
  235. package/docs/classes/SegmentTreeNode.html +62 -140
  236. package/docs/classes/SinglyLinkedList.html +53 -58
  237. package/docs/classes/SinglyLinkedListNode.html +25 -20
  238. package/docs/classes/SkipLinkedList.html +18 -13
  239. package/docs/classes/SplayTree.html +18 -13
  240. package/docs/classes/Stack.html +31 -26
  241. package/docs/classes/TreeMap.html +155 -0
  242. package/docs/classes/TreeMultiSet.html +541 -388
  243. package/docs/classes/TreeNode.html +125 -35
  244. package/docs/classes/TreeSet.html +155 -0
  245. package/docs/classes/Trie.html +30 -25
  246. package/docs/classes/TrieNode.html +33 -28
  247. package/docs/classes/TwoThreeTree.html +18 -13
  248. package/docs/classes/UndirectedEdge.html +87 -80
  249. package/docs/classes/UndirectedGraph.html +356 -178
  250. package/docs/classes/UndirectedVertex.html +63 -52
  251. package/docs/classes/Vector2D.html +45 -40
  252. package/docs/enums/CP.html +21 -16
  253. package/docs/enums/FamilyPosition.html +21 -16
  254. package/docs/enums/LoopType.html +20 -15
  255. package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +47 -44
  256. package/docs/index.html +203 -69
  257. package/docs/interfaces/{PriorityQueueOptions.html → IBinaryTree.html} +49 -40
  258. package/docs/interfaces/IBinaryTreeNode.html +383 -0
  259. package/docs/interfaces/IDirectedGraph.html +24 -19
  260. package/docs/interfaces/IGraph.html +122 -89
  261. package/docs/interfaces/{HeapOptions.html → IUNDirectedGraph.html} +26 -53
  262. package/docs/modules.html +33 -23
  263. package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +31 -22
  264. package/docs/types/BSTComparator.html +18 -13
  265. package/docs/types/BSTDeletedResult.html +23 -18
  266. package/docs/types/BinaryTreeDeleted.html +23 -18
  267. package/docs/types/BinaryTreeNodeId.html +18 -13
  268. package/docs/types/BinaryTreeNodePropertyName.html +18 -13
  269. package/docs/types/DFSOrderPattern.html +18 -13
  270. package/docs/types/DijkstraResult.html +18 -13
  271. package/docs/types/Direction.html +18 -13
  272. package/docs/types/{DoublyLinkedListGetBy.html → EdgeId.html} +22 -17
  273. package/docs/types/{TrlFn.html → HeapOptions.html} +33 -20
  274. package/docs/types/{TrlAsyncFn.html → NavigatorParams.html} +46 -20
  275. package/docs/types/NodeOrPropertyName.html +18 -13
  276. package/docs/types/PriorityQueueComparator.html +18 -13
  277. package/docs/types/PriorityQueueDFSOrderPattern.html +18 -13
  278. package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +32 -20
  279. package/docs/types/RecursiveAVLTreeNode.html +135 -0
  280. package/docs/types/RecursiveBSTNode.html +135 -0
  281. package/docs/types/RecursiveBinaryTreeNode.html +135 -0
  282. package/docs/types/ResultByProperty.html +21 -16
  283. package/docs/types/ResultsByProperty.html +21 -16
  284. package/docs/types/SegmentTreeNodeVal.html +18 -13
  285. package/docs/types/TopologicalStatus.html +18 -13
  286. package/docs/types/TreeMultiSetDeletedResult.html +23 -18
  287. package/docs/types/Turning.html +18 -13
  288. package/docs/types/VertexId.html +18 -13
  289. package/notes/note.md +12 -1
  290. package/package.json +11 -3
  291. package/tsconfig.json +2 -2
  292. package/docs/interfaces/NavigatorParams.html +0 -197
  293. package/docs/types/Thunk.html +0 -133
@@ -18,6 +18,13 @@ var BinaryIndexedTree = /** @class */ (function () {
18
18
  function BinaryIndexedTree(n) {
19
19
  this._sumTree = new Array(n + 1).fill(0);
20
20
  }
21
+ Object.defineProperty(BinaryIndexedTree.prototype, "sumTree", {
22
+ get: function () {
23
+ return this._sumTree;
24
+ },
25
+ enumerable: false,
26
+ configurable: true
27
+ });
21
28
  BinaryIndexedTree.lowBit = function (x) {
22
29
  return x & (-x);
23
30
  };
@@ -63,6 +70,9 @@ var BinaryIndexedTree = /** @class */ (function () {
63
70
  throw 'Index out of bounds';
64
71
  return this.getPrefixSum(end) - this.getPrefixSum(start);
65
72
  };
73
+ BinaryIndexedTree.prototype._setSumTree = function (value) {
74
+ this._sumTree = value;
75
+ };
66
76
  return BinaryIndexedTree;
67
77
  }());
68
78
  exports.BinaryIndexedTree = BinaryIndexedTree;
@@ -5,7 +5,8 @@
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';
8
+ import type { BinaryTreeDeleted, BinaryTreeNodeId, BinaryTreeNodePropertyName, DFSOrderPattern, NodeOrPropertyName, RecursiveBinaryTreeNode, ResultsByProperty } from '../types';
9
+ import { IBinaryTree, IBinaryTreeNode } from '../interfaces';
9
10
  export declare enum FamilyPosition {
10
11
  root = 0,
11
12
  left = 1,
@@ -21,77 +22,37 @@ export declare enum LoopType {
21
22
  iterative = 1,
22
23
  recursive = 2
23
24
  }
24
- export declare class BinaryTreeNode<T> {
25
+ export declare class BinaryTreeNode<T, FAMILY extends BinaryTreeNode<T, FAMILY> = RecursiveBinaryTreeNode<T>> implements IBinaryTreeNode<T, FAMILY> {
25
26
  constructor(id: BinaryTreeNodeId, val: T, count?: number);
26
- protected _id: BinaryTreeNodeId;
27
+ private _id;
27
28
  get id(): BinaryTreeNodeId;
28
29
  set id(v: BinaryTreeNodeId);
29
- protected _val: T;
30
+ private _val;
30
31
  get val(): T;
31
32
  set val(v: T);
32
- protected _left?: BinaryTreeNode<T> | null;
33
- get left(): BinaryTreeNode<T> | null | undefined;
34
- set left(v: BinaryTreeNode<T> | null | undefined);
35
- protected _right?: BinaryTreeNode<T> | null;
36
- get right(): BinaryTreeNode<T> | null | undefined;
37
- set right(v: BinaryTreeNode<T> | null | undefined);
38
- protected _parent: BinaryTreeNode<T> | null | undefined;
39
- get parent(): BinaryTreeNode<T> | null | undefined;
40
- set parent(v: BinaryTreeNode<T> | null | undefined);
41
- protected _familyPosition: FamilyPosition;
33
+ private _left?;
34
+ get left(): FAMILY | null | undefined;
35
+ set left(v: FAMILY | null | undefined);
36
+ private _right?;
37
+ get right(): FAMILY | null | undefined;
38
+ set right(v: FAMILY | null | undefined);
39
+ private _parent;
40
+ get parent(): FAMILY | null | undefined;
41
+ set parent(v: FAMILY | null | undefined);
42
+ private _familyPosition;
42
43
  get familyPosition(): FamilyPosition;
43
44
  set familyPosition(v: FamilyPosition);
44
- protected _count: number;
45
+ private _count;
45
46
  get count(): number;
46
47
  set count(v: number);
47
- protected _height: number;
48
+ private _height;
48
49
  get height(): number;
49
50
  set height(v: number);
50
- /**
51
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
52
- */
53
- getId(): BinaryTreeNodeId;
54
- /**
55
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
56
- */
57
- getVal(): T;
58
- /**
59
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
60
- */
61
- getLeft(): BinaryTreeNode<T> | null | undefined;
62
- /**
63
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
64
- */
65
- getRight(): BinaryTreeNode<T> | null | undefined;
66
- /**
67
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
68
- */
69
- getParent(): BinaryTreeNode<T> | null | undefined;
70
- /**
71
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
72
- */
73
- getFamilyPosition(): FamilyPosition;
74
- /**
75
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
76
- */
77
- getCount(): number;
78
- /**
79
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
80
- */
81
- getHeight(): number;
82
- swapLocation(swapNode: BinaryTreeNode<T>): BinaryTreeNode<T>;
83
- clone(): BinaryTreeNode<T>;
51
+ _createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
52
+ swapLocation(swapNode: FAMILY): FAMILY;
53
+ clone(): FAMILY | null;
84
54
  }
85
- export declare class BinaryTree<T> {
86
- protected _loopType: LoopType;
87
- protected _visitedId: BinaryTreeNodeId[];
88
- protected _visitedVal: Array<T>;
89
- protected _visitedNode: BinaryTreeNode<T>[];
90
- protected _visitedCount: number[];
91
- protected _visitedLeftSum: number[];
92
- private readonly _autoIncrementId;
93
- private _maxId;
94
- private readonly _isDuplicatedVal;
55
+ export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode<number>> implements IBinaryTree<N> {
95
56
  /**
96
57
  * The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and
97
58
  * isDuplicatedVal based on the provided options.
@@ -102,41 +63,42 @@ export declare class BinaryTree<T> {
102
63
  autoIncrementId?: boolean;
103
64
  isDuplicatedVal?: boolean;
104
65
  });
105
- protected _root: BinaryTreeNode<T> | null;
106
- get root(): BinaryTreeNode<T> | null;
107
- protected set root(v: BinaryTreeNode<T> | null);
108
- protected _size: number;
66
+ private _loopType;
67
+ get loopType(): LoopType;
68
+ private _visitedId;
69
+ get visitedId(): BinaryTreeNodeId[];
70
+ private _visitedVal;
71
+ get visitedVal(): Array<N['val']>;
72
+ private _visitedNode;
73
+ get visitedNode(): N[];
74
+ private _visitedCount;
75
+ get visitedCount(): number[];
76
+ private _visitedLeftSum;
77
+ get visitedLeftSum(): number[];
78
+ private _autoIncrementId;
79
+ get autoIncrementId(): boolean;
80
+ private _maxId;
81
+ get maxId(): number;
82
+ private _isDuplicatedVal;
83
+ get isDuplicatedVal(): boolean;
84
+ private _root;
85
+ get root(): N | null;
86
+ private _size;
109
87
  get size(): number;
110
- protected set size(v: number);
111
- protected _count: number;
88
+ private _count;
112
89
  get count(): number;
113
- protected set count(v: number);
114
- /**
115
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Getters (using the same name as the property) while utilizing separate method names for Setters.
116
- * @returns The method is returning either a BinaryTreeNode object of type T or null.
117
- */
118
- getRoot(): BinaryTreeNode<T> | null;
119
- /**
120
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
121
- */
122
- getSize(): number;
123
- /**
124
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
125
- */
126
- getCount(): number;
127
90
  /**
128
- * The function creates a new binary tree node with the given id, value, and count, or returns null if the value is
129
- * null.
91
+ * The function creates a new binary tree node with the given id, value, and count if the value is not null, otherwise
92
+ * it returns null.
130
93
  * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
131
- * `BinaryTreeNodeId`, which could be a string or a number, depending on how you want to identify your nodes.
132
- * @param {T | null} val - The `val` parameter represents the value to be stored in the binary tree node. It can be of
133
- * any type `T` or `null`.
134
- * @param {number} [count] - The count parameter is an optional parameter that represents the number of occurrences of
135
- * the value in the binary tree node. It is of type number.
136
- * @returns The function `createNode` returns a `BinaryTreeNode<T>` object if the `val` parameter is not null.
137
- * Otherwise, it returns null.
94
+ * `BinaryTreeNodeId`.
95
+ * @param {N | null} val - The `val` parameter represents the value of the node. It can be of type `N` (generic type)
96
+ * or `null`.
97
+ * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
98
+ * of occurrences of the value in the binary tree node. If not provided, the default value is `undefined`.
99
+ * @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
138
100
  */
139
- createNode(id: BinaryTreeNodeId, val: T | null, count?: number): BinaryTreeNode<T> | null;
101
+ _createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
140
102
  /**
141
103
  * The clear function resets the state of an object by setting its properties to their initial values.
142
104
  */
@@ -151,38 +113,38 @@ export declare class BinaryTree<T> {
151
113
  * already exists.
152
114
  * @param {BinaryTreeNodeId} id - The id parameter is the identifier of the binary tree node. It is used to uniquely
153
115
  * identify each node in the binary tree.
154
- * @param {T} val - The value to be inserted into the binary tree.
116
+ * @param {N} val - The value to be inserted into the binary tree.
155
117
  * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
156
118
  * value should be inserted into the binary tree. If not provided, it defaults to 1.
157
- * @returns The function `add` returns a `BinaryTreeNode<T>` object if a new node is inserted, or `null` if no new node
119
+ * @returns The function `add` returns a `N` object if a new node is inserted, or `null` if no new node
158
120
  * is inserted, or `undefined` if the insertion fails.
159
121
  */
160
- add(id: BinaryTreeNodeId, val: T, count?: number): BinaryTreeNode<T> | null | undefined;
122
+ add(id: BinaryTreeNodeId, val: N['val'], count?: number): N | null | undefined;
161
123
  /**
162
124
  * The function inserts a new node into a binary tree as the left or right child of a given parent node.
163
- * @param {BinaryTreeNode<T> | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
125
+ * @param {N | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
164
126
  * `null`. It represents the node that needs to be inserted into the binary tree.
165
127
  * @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node
166
128
  * will be inserted as a child.
167
129
  * @returns The method returns the newly inserted node, either as the left child or the right child of the parent node.
168
130
  */
169
- addTo(newNode: BinaryTreeNode<T> | null, parent: BinaryTreeNode<T>): BinaryTreeNode<T> | null | undefined;
131
+ addTo(newNode: N | null, parent: N): N | null | undefined;
170
132
  /**
171
133
  * The `addMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
172
134
  * null/undefined values.
173
- * @param {T[] | BinaryTreeNode<T>[]} data - The `data` parameter can be either an array of elements of type `T` or an
174
- * array of `BinaryTreeNode<T>` objects.
175
- * @returns The function `addMany` returns an array of `BinaryTreeNode<T>`, `null`, or `undefined` values.
135
+ * @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
136
+ * array of `N` objects.
137
+ * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
176
138
  */
177
- addMany(data: T[] | BinaryTreeNode<T>[]): (BinaryTreeNode<T> | null | undefined)[];
139
+ addMany(data: N[] | Array<N['val']>): (N | null | undefined)[];
178
140
  /**
179
141
  * The `fill` function clears the current data and inserts new data, returning a boolean indicating if the insertion
180
142
  * was successful.
181
- * @param {T[] | BinaryTreeNode<T>[]} data - The `data` parameter can be either an array of elements of type `T` or an
182
- * array of `BinaryTreeNode<T>` objects.
143
+ * @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
144
+ * array of `N` objects.
183
145
  * @returns The method is returning a boolean value.
184
146
  */
185
- fill(data: T[] | BinaryTreeNode<T>[]): boolean;
147
+ fill(data: N[] | Array<N['val']>): boolean;
186
148
  /**
187
149
  * The function removes a node from a binary tree and returns information about the deleted node.
188
150
  * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to remove.
@@ -194,102 +156,102 @@ export declare class BinaryTree<T> {
194
156
  * "needBalanced". The "deleted" property contains the deleted node or undefined if no node was deleted. The
195
157
  * "needBalanced" property is always null.
196
158
  */
197
- remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<T>[];
159
+ remove(id: BinaryTreeNodeId, ignoreCount?: boolean): BinaryTreeDeleted<N>[];
198
160
  /**
199
161
  * The function calculates the depth of a binary tree node by traversing its parent nodes.
200
- * @param node - BinaryTreeNode<T> - This is the node for which we want to calculate the depth. It is a generic type,
162
+ * @param node - N - This is the node for which we want to calculate the depth. It is a generic type,
201
163
  * meaning it can represent any type of data that we want to store in the node.
202
164
  * @returns The depth of the given binary tree node.
203
165
  */
204
- getDepth(node: BinaryTreeNode<T>): number;
166
+ getDepth(node: N): number;
205
167
  /**
206
168
  * The `getHeight` function calculates the maximum height of a binary tree using either a recursive or iterative
207
169
  * approach.
208
- * @param {BinaryTreeNode<T> | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
209
- * `BinaryTreeNode<T> | null`. It represents the starting node from which to calculate the height of the binary tree.
170
+ * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
171
+ * `N | null`. It represents the starting node from which to calculate the height of the binary tree.
210
172
  * If no value is provided for `beginRoot`, the function will use the `root` property of the class instance as
211
173
  * @returns the height of the binary tree.
212
174
  */
213
- getHeight(beginRoot?: BinaryTreeNode<T> | null): number;
175
+ getHeight(beginRoot?: N | null): number;
214
176
  /**
215
177
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
216
178
  * approach.
217
- * @param {BinaryTreeNode<T> | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
218
- * `BinaryTreeNode<T> | null`. It represents the starting node from which to calculate the minimum height of the binary
179
+ * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
180
+ * `N | null`. It represents the starting node from which to calculate the minimum height of the binary
219
181
  * tree. If no value is provided for `beginRoot`, the function will use the root node of the binary tree.
220
182
  * @returns The function `getMinHeight` returns the minimum height of the binary tree.
221
183
  */
222
- getMinHeight(beginRoot?: BinaryTreeNode<T> | null): number;
184
+ getMinHeight(beginRoot?: N | null): number;
223
185
  /**
224
186
  * The function checks if a binary tree is balanced by comparing the minimum height and the maximum height of the tree.
225
- * @param {BinaryTreeNode<T> | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
226
- * of type `BinaryTreeNode<T> | null`, which means it can either be a `BinaryTreeNode` object or `null`.
187
+ * @param {N | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
188
+ * of type `N | null`, which means it can either be a `BinaryTreeNode` object or `null`.
227
189
  * @returns The method is returning a boolean value.
228
190
  */
229
- isBalanced(beginRoot?: BinaryTreeNode<T> | null): boolean;
191
+ isBalanced(beginRoot?: N | null): boolean;
230
192
  /**
231
193
  * The function `getNodes` returns an array of binary tree nodes that match a given property value, with options for
232
194
  * searching recursively or iteratively.
233
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
234
- * generic type `T`. It represents the property of the binary tree node that you want to search for.
195
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
196
+ * generic type `N`. It represents the property of the binary tree node that you want to search for.
235
197
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
236
198
  * specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
237
199
  * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
238
200
  * return only one node that matches the `nodeProperty` or `propertyName` criteria. If `onlyOne` is set to `true`, the
239
201
  * function will stop traversing the tree and return the first matching node. If `
240
- * @returns The function `getNodes` returns an array of `BinaryTreeNode<T> | null | undefined` objects.
202
+ * @returns The function `getNodes` returns an array of `N | null | undefined` objects.
241
203
  */
242
- getNodes(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): (BinaryTreeNode<T> | null | undefined)[];
204
+ getNodes(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): (N | null | undefined)[];
243
205
  /**
244
206
  * The function checks if a binary tree node has a specific property or if any node in the tree has a specific
245
207
  * property.
246
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
247
- * generic type `T`. It represents the property of a binary tree node that you want to check.
208
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
209
+ * generic type `N`. It represents the property of a binary tree node that you want to check.
248
210
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
249
211
  * specifies the name of the property to check for in the nodes.
250
212
  * @returns a boolean value.
251
213
  */
252
- has(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): boolean;
214
+ has(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): boolean;
253
215
  /**
254
216
  * The function returns the first binary tree node that matches the given property name and value, or null if no match
255
217
  * is found.
256
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
257
- * generic type `T`. It represents the property of the binary tree node that you want to search for.
218
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
219
+ * generic type `N`. It represents the property of the binary tree node that you want to search for.
258
220
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
259
221
  * specifies the property of the binary tree node to search for. If not provided, it defaults to `'id'`.
260
222
  * @returns a BinaryTreeNode object or null.
261
223
  */
262
- get(nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName): BinaryTreeNode<T> | null;
224
+ get(nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName): N | null;
263
225
  /**
264
226
  * The function getPathToRoot returns an array of BinaryTreeNode objects representing the path from a given node to the
265
227
  * root of a binary tree.
266
228
  * @param node - The `node` parameter is a BinaryTreeNode object.
267
- * @returns The function `getPathToRoot` returns an array of `BinaryTreeNode<T>` objects, representing the path from
229
+ * @returns The function `getPathToRoot` returns an array of `N` objects, representing the path from
268
230
  * the given `node` to the root of the binary tree.
269
231
  */
270
- getPathToRoot(node: BinaryTreeNode<T>): BinaryTreeNode<T>[];
271
- getLeftMost(): BinaryTreeNode<T> | null;
272
- getLeftMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
273
- getRightMost(): BinaryTreeNode<T> | null;
274
- getRightMost(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
232
+ getPathToRoot(node: N): N[];
233
+ getLeftMost(): N | null;
234
+ getLeftMost(node: N): N;
235
+ getRightMost(): N | null;
236
+ getRightMost(node: N): N;
275
237
  /**
276
238
  * The `isBST` function checks if a binary tree is a binary search tree.
277
- * @param {BinaryTreeNode<T> | null} [node] - The `node` parameter is an optional parameter of type `BinaryTreeNode<T>
239
+ * @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
278
240
  * | null`. It represents the root node of the binary search tree (BST) that we want to check for validity. If no node
279
241
  * is provided, the function will default to using the root node of the BST instance that
280
242
  * @returns The `isBST` function returns a boolean value. It returns `true` if the binary tree is a valid binary search
281
243
  * tree, and `false` otherwise.
282
244
  */
283
- isBST(node?: BinaryTreeNode<T> | null): boolean;
245
+ isBST(node?: N | null): boolean;
284
246
  /**
285
247
  * The function calculates the size and count of a subtree in a binary tree using either recursive or iterative
286
248
  * traversal.
287
- * @param {BinaryTreeNode<T> | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
249
+ * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
288
250
  * tree.
289
251
  * @returns The function `getSubTreeSizeAndCount` returns an array `[number, number]`. The first element of the array
290
252
  * represents the size of the subtree, and the second element represents the count of the nodes in the subtree.
291
253
  */
292
- getSubTreeSizeAndCount(subTreeRoot: BinaryTreeNode<T> | null | undefined): [number, number];
254
+ getSubTreeSizeAndCount(subTreeRoot: N | null | undefined): [number, number];
293
255
  /**
294
256
  * The function `subTreeSum` calculates the sum of a specified property in a binary tree, either recursively or
295
257
  * iteratively.
@@ -300,7 +262,7 @@ export declare class BinaryTree<T> {
300
262
  * provided, it defaults to `'val'`.
301
263
  * @returns a number, which is the sum of the values of the nodes in the subtree rooted at `subTreeRoot`.
302
264
  */
303
- subTreeSum(subTreeRoot: BinaryTreeNode<T>, propertyName?: BinaryTreeNodePropertyName): number;
265
+ subTreeSum(subTreeRoot: N, propertyName?: BinaryTreeNodePropertyName): number;
304
266
  /**
305
267
  * The function `subTreeAdd` adds a specified delta value to a property of each node in a binary tree.
306
268
  * @param subTreeRoot - The `subTreeRoot` parameter is the root node of the subtree where the values will be modified.
@@ -310,43 +272,55 @@ export declare class BinaryTree<T> {
310
272
  * specifies the property of the `BinaryTreeNode` that should be modified. It defaults to `'id'` if not provided.
311
273
  * @returns a boolean value, which is `true`.
312
274
  */
313
- subTreeAdd(subTreeRoot: BinaryTreeNode<T>, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
275
+ subTreeAdd(subTreeRoot: N, delta: number, propertyName?: BinaryTreeNodePropertyName): boolean;
314
276
  BFS(): BinaryTreeNodeId[];
315
277
  BFS(nodeOrPropertyName: 'id'): BinaryTreeNodeId[];
316
- BFS(nodeOrPropertyName: 'val'): T[];
317
- BFS(nodeOrPropertyName: 'node'): BinaryTreeNode<T>[];
278
+ BFS(nodeOrPropertyName: 'val'): N['val'][];
279
+ BFS(nodeOrPropertyName: 'node'): N[];
318
280
  BFS(nodeOrPropertyName: 'count'): number[];
319
281
  DFS(): BinaryTreeNodeId[];
320
282
  DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
321
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
322
- DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
283
+ DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
284
+ DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
323
285
  DFS(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
324
286
  DFSIterative(): BinaryTreeNodeId[];
325
287
  DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
326
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
327
- DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
288
+ DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
289
+ DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
328
290
  DFSIterative(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
329
- levelIterative(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[];
330
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
331
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[];
332
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
333
- levelIterative(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[];
334
- listLevels(node: BinaryTreeNode<T> | null): BinaryTreeNodeId[][];
335
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
336
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'val'): T[][];
337
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[][];
338
- listLevels(node: BinaryTreeNode<T> | null, nodeOrPropertyName?: 'count'): number[][];
291
+ levelIterative(node: N | null): BinaryTreeNodeId[];
292
+ levelIterative(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
293
+ levelIterative(node: N | null, nodeOrPropertyName?: 'val'): N['val'][];
294
+ levelIterative(node: N | null, nodeOrPropertyName?: 'node'): N[];
295
+ levelIterative(node: N | null, nodeOrPropertyName?: 'count'): number[];
296
+ listLevels(node: N | null): BinaryTreeNodeId[][];
297
+ listLevels(node: N | null, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[][];
298
+ listLevels(node: N | null, nodeOrPropertyName?: 'val'): N['val'][][];
299
+ listLevels(node: N | null, nodeOrPropertyName?: 'node'): N[][];
300
+ listLevels(node: N | null, nodeOrPropertyName?: 'count'): number[][];
339
301
  /**
340
302
  * The function returns the predecessor of a given node in a binary tree.
341
303
  * @param node - The parameter `node` is a BinaryTreeNode object, representing a node in a binary tree.
342
304
  * @returns the predecessor of the given node in a binary tree.
343
305
  */
344
- getPredecessor(node: BinaryTreeNode<T>): BinaryTreeNode<T>;
306
+ getPredecessor(node: N): N;
345
307
  morris(): BinaryTreeNodeId[];
346
308
  morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'id'): BinaryTreeNodeId[];
347
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): T[];
348
- morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): BinaryTreeNode<T>[];
309
+ morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'val'): N[];
310
+ morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'node'): N[];
349
311
  morris(pattern?: DFSOrderPattern, nodeOrPropertyName?: 'count'): number[];
312
+ protected _setLoopType(value: LoopType): void;
313
+ protected _setVisitedId(value: BinaryTreeNodeId[]): void;
314
+ protected _setVisitedVal(value: Array<N>): void;
315
+ protected _setVisitedNode(value: N[]): void;
316
+ protected setVisitedCount(value: number[]): void;
317
+ protected _setVisitedLeftSum(value: number[]): void;
318
+ protected _setAutoIncrementId(value: boolean): void;
319
+ protected _setMaxId(value: number): void;
320
+ protected _setIsDuplicatedVal(value: boolean): void;
321
+ protected _setRoot(v: N | null): void;
322
+ protected _setSize(v: number): void;
323
+ protected _setCount(v: number): void;
350
324
  /**
351
325
  * The function resets the values of several arrays used for tracking visited nodes and their properties.
352
326
  */
@@ -355,9 +329,9 @@ export declare class BinaryTree<T> {
355
329
  * The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
356
330
  * a result array.
357
331
  * @param cur - The current binary tree node that is being checked.
358
- * @param {(BinaryTreeNode<T> | null | undefined)[]} result - An array that stores the matching nodes found during the
332
+ * @param {(N | null | undefined)[]} result - An array that stores the matching nodes found during the
359
333
  * traversal.
360
- * @param {BinaryTreeNodeId | T} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
334
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
361
335
  * the binary tree nodes. It can be either the `id`, `count`, or `val` property of the node.
362
336
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
363
337
  * specifies the property of the `BinaryTreeNode` object that you want to compare with the `nodeProperty` value. It can
@@ -367,16 +341,16 @@ export declare class BinaryTree<T> {
367
341
  * `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
368
342
  * @returns a boolean value indicating whether or not a node was pushed into the result array.
369
343
  */
370
- protected _pushByPropertyNameStopOrNot(cur: BinaryTreeNode<T>, result: (BinaryTreeNode<T> | null | undefined)[], nodeProperty: BinaryTreeNodeId | T, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
344
+ protected _pushByPropertyNameStopOrNot(cur: N, result: (N | null | undefined)[], nodeProperty: BinaryTreeNodeId | N, propertyName?: BinaryTreeNodePropertyName, onlyOne?: boolean): boolean | undefined;
371
345
  /**
372
346
  * The function `_accumulatedByPropertyName` pushes a property value of a binary tree node into an array based on the
373
347
  * provided property name or a default property name.
374
- * @param node - The `node` parameter is of type `BinaryTreeNode<T>`, which represents a node in a binary tree.
348
+ * @param node - The `node` parameter is of type `N`, which represents a node in a binary tree.
375
349
  * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
376
350
  * can be either a string representing a property name or a reference to a node object. If it is a string, it specifies
377
351
  * the property name of the node that should be accumulated. If it is a node object, it specifies the node itself
378
352
  */
379
- protected _accumulatedByPropertyName(node: BinaryTreeNode<T>, nodeOrPropertyName?: NodeOrPropertyName): void;
353
+ protected _accumulatedByPropertyName(node: N, nodeOrPropertyName?: NodeOrPropertyName): void;
380
354
  /**
381
355
  * The function `_getResultByPropertyName` returns different results based on the provided property name or defaulting
382
356
  * to 'id'.
@@ -384,5 +358,5 @@ export declare class BinaryTree<T> {
384
358
  * can accept a value of type `NodeOrPropertyName`.
385
359
  * @returns The method returns an object of type `ResultsByProperty<T>`.
386
360
  */
387
- protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<T>;
361
+ protected _getResultByPropertyName(nodeOrPropertyName?: NodeOrPropertyName): ResultsByProperty<N>;
388
362
  }