data-structure-typed 1.18.7 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +208 -419
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +198 -167
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +413 -398
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +24 -16
  5. package/dist/data-structures/binary-tree/avl-tree.js +23 -17
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
  7. package/dist/data-structures/binary-tree/binary-tree.js +12 -27
  8. package/dist/data-structures/binary-tree/bst.d.ts +66 -90
  9. package/dist/data-structures/binary-tree/bst.js +85 -163
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -17
  11. package/dist/data-structures/binary-tree/rb-tree.js +5 -17
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +187 -18
  13. package/dist/data-structures/binary-tree/tree-multiset.js +716 -39
  14. package/dist/data-structures/graph/abstract-graph.d.ts +112 -52
  15. package/dist/data-structures/graph/abstract-graph.js +138 -72
  16. package/dist/data-structures/graph/directed-graph.d.ts +104 -101
  17. package/dist/data-structures/graph/directed-graph.js +134 -129
  18. package/dist/data-structures/graph/undirected-graph.d.ts +66 -65
  19. package/dist/data-structures/graph/undirected-graph.js +107 -106
  20. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +12 -18
  21. package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
  22. package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
  23. package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
  24. package/dist/data-structures/interfaces/bst.d.ts +4 -5
  25. package/dist/data-structures/interfaces/rb-tree.d.ts +2 -3
  26. package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
  27. package/dist/data-structures/tree/tree.d.ts +1 -4
  28. package/dist/data-structures/tree/tree.js +1 -12
  29. package/dist/data-structures/types/abstract-binary-tree.d.ts +10 -6
  30. package/dist/data-structures/types/abstract-binary-tree.js +9 -5
  31. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  32. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  33. package/dist/data-structures/types/bst.d.ts +1 -1
  34. package/dist/data-structures/types/bst.js +1 -1
  35. package/dist/data-structures/types/directed-graph.js +1 -1
  36. package/dist/data-structures/types/helpers.d.ts +1 -8
  37. package/dist/data-structures/types/rb-tree.d.ts +2 -0
  38. package/dist/data-structures/types/rb-tree.js +1 -1
  39. package/dist/data-structures/types/tree-multiset.d.ts +5 -5
  40. package/dist/utils/index.d.ts +1 -0
  41. package/dist/utils/index.js +1 -0
  42. package/dist/utils/types/index.d.ts +1 -0
  43. package/dist/utils/types/index.js +1 -0
  44. package/dist/utils/types/validate-type.d.ts +19 -0
  45. package/dist/utils/types/validate-type.js +2 -0
  46. package/dist/utils/utils.d.ts +2 -2
  47. package/dist/utils/utils.js +0 -62
  48. package/dist/utils/validate-type.d.ts +45 -0
  49. package/dist/utils/validate-type.js +58 -0
  50. package/package.json +5 -2
  51. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  52. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  53. package/backup/recursive-type/src/assets/logo.png +0 -0
  54. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  55. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
  56. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
  57. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
  58. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
  59. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
  60. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
  61. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  62. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  63. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  64. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
  65. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
  66. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
  67. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
  68. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
  69. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  70. package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
  71. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
  72. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  73. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  74. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  75. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  76. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  77. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  78. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  79. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  80. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  81. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  82. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  83. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  84. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  85. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  86. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
  87. package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
  88. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
  89. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
  90. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
  91. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
  92. package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
  93. package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
  94. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
  95. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
  96. package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
  97. package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
  98. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
  99. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
  100. package/backup/recursive-type/src/data-structures/index.ts +0 -15
  101. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
  102. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
  103. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
  104. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
  105. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
  106. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
  107. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
  108. package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
  109. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
  110. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
  111. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
  112. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
  113. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
  114. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
  115. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  116. package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
  117. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
  118. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
  119. package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
  120. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
  121. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
  122. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
  123. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
  124. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
  125. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
  126. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
  127. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
  128. package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
  129. package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
  130. package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
  131. package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
  132. package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
  133. package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
  134. package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
  135. package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
  136. package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
  137. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
  138. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
  139. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
  140. package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
  141. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
  142. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
  143. package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
  144. package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
  145. package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
  146. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
  147. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
  148. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
  149. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
  150. package/backup/recursive-type/src/index.ts +0 -1
  151. package/backup/recursive-type/src/utils/index.ts +0 -2
  152. package/backup/recursive-type/src/utils/types/index.ts +0 -1
  153. package/backup/recursive-type/src/utils/types/utils.ts +0 -6
  154. package/backup/recursive-type/src/utils/utils.ts +0 -78
  155. package/docs/.nojekyll +0 -1
  156. package/docs/assets/highlight.css +0 -92
  157. package/docs/assets/main.js +0 -58
  158. package/docs/assets/search.js +0 -1
  159. package/docs/assets/style.css +0 -1367
  160. package/docs/classes/AVLTree.html +0 -2451
  161. package/docs/classes/AVLTreeNode.html +0 -499
  162. package/docs/classes/AaTree.html +0 -172
  163. package/docs/classes/AbstractBinaryTree.html +0 -2118
  164. package/docs/classes/AbstractBinaryTreeNode.html +0 -524
  165. package/docs/classes/AbstractEdge.html +0 -295
  166. package/docs/classes/AbstractGraph.html +0 -1043
  167. package/docs/classes/AbstractVertex.html +0 -258
  168. package/docs/classes/ArrayDeque.html +0 -439
  169. package/docs/classes/BST.html +0 -2297
  170. package/docs/classes/BSTNode.html +0 -503
  171. package/docs/classes/BTree.html +0 -172
  172. package/docs/classes/BinaryIndexedTree.html +0 -341
  173. package/docs/classes/BinaryTree.html +0 -2133
  174. package/docs/classes/BinaryTreeNode.html +0 -501
  175. package/docs/classes/Character.html +0 -220
  176. package/docs/classes/CoordinateMap.html +0 -483
  177. package/docs/classes/CoordinateSet.html +0 -444
  178. package/docs/classes/Deque.html +0 -975
  179. package/docs/classes/DirectedEdge.html +0 -366
  180. package/docs/classes/DirectedGraph.html +0 -1443
  181. package/docs/classes/DirectedVertex.html +0 -254
  182. package/docs/classes/DoublyLinkedList.html +0 -968
  183. package/docs/classes/DoublyLinkedListNode.html +0 -297
  184. package/docs/classes/HashTable.html +0 -172
  185. package/docs/classes/Heap.html +0 -423
  186. package/docs/classes/HeapItem.html +0 -255
  187. package/docs/classes/Matrix2D.html +0 -502
  188. package/docs/classes/MatrixNTI2D.html +0 -240
  189. package/docs/classes/MaxHeap.html +0 -436
  190. package/docs/classes/MaxPriorityQueue.html +0 -836
  191. package/docs/classes/MinHeap.html +0 -437
  192. package/docs/classes/MinPriorityQueue.html +0 -838
  193. package/docs/classes/Navigator.html +0 -313
  194. package/docs/classes/ObjectDeque.html +0 -455
  195. package/docs/classes/Pair.html +0 -172
  196. package/docs/classes/PriorityQueue.html +0 -760
  197. package/docs/classes/Queue.html +0 -392
  198. package/docs/classes/RBTree.html +0 -2388
  199. package/docs/classes/RBTreeNode.html +0 -516
  200. package/docs/classes/SegmentTree.html +0 -434
  201. package/docs/classes/SegmentTreeNode.html +0 -357
  202. package/docs/classes/SinglyLinkedList.html +0 -788
  203. package/docs/classes/SinglyLinkedListNode.html +0 -270
  204. package/docs/classes/SkipLinkedList.html +0 -172
  205. package/docs/classes/SplayTree.html +0 -172
  206. package/docs/classes/Stack.html +0 -368
  207. package/docs/classes/TreeMap.html +0 -172
  208. package/docs/classes/TreeMultiSet.html +0 -2297
  209. package/docs/classes/TreeMultiSetNode.html +0 -499
  210. package/docs/classes/TreeNode.html +0 -343
  211. package/docs/classes/TreeSet.html +0 -172
  212. package/docs/classes/Trie.html +0 -372
  213. package/docs/classes/TrieNode.html +0 -280
  214. package/docs/classes/TwoThreeTree.html +0 -172
  215. package/docs/classes/UndirectedEdge.html +0 -337
  216. package/docs/classes/UndirectedGraph.html +0 -1210
  217. package/docs/classes/UndirectedVertex.html +0 -254
  218. package/docs/classes/Vector2D.html +0 -805
  219. package/docs/enums/CP.html +0 -181
  220. package/docs/enums/FamilyPosition.html +0 -181
  221. package/docs/enums/LoopType.html +0 -182
  222. package/docs/enums/RBColor.html +0 -174
  223. package/docs/enums/TopologicalProperty.html +0 -181
  224. package/docs/index.html +0 -645
  225. package/docs/interfaces/IAVLTree.html +0 -1378
  226. package/docs/interfaces/IAVLTreeNode.html +0 -405
  227. package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
  228. package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
  229. package/docs/interfaces/IAbstractGraph.html +0 -433
  230. package/docs/interfaces/IBST.html +0 -1271
  231. package/docs/interfaces/IBSTNode.html +0 -408
  232. package/docs/interfaces/IDirectedGraph.html +0 -572
  233. package/docs/interfaces/IUNDirectedGraph.html +0 -465
  234. package/docs/modules.html +0 -262
  235. package/docs/types/AVLTreeOptions.html +0 -150
  236. package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
  237. package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
  238. package/docs/types/AbstractBinaryTreeOptions.html +0 -156
  239. package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
  240. package/docs/types/BSTComparator.html +0 -162
  241. package/docs/types/BSTOptions.html +0 -152
  242. package/docs/types/BinaryTreeDeletedResult.html +0 -159
  243. package/docs/types/BinaryTreeNodeId.html +0 -147
  244. package/docs/types/BinaryTreeNodePropertyName.html +0 -147
  245. package/docs/types/BinaryTreeOptions.html +0 -150
  246. package/docs/types/DFSOrderPattern.html +0 -147
  247. package/docs/types/DijkstraResult.html +0 -167
  248. package/docs/types/Direction.html +0 -147
  249. package/docs/types/EdgeId.html +0 -147
  250. package/docs/types/HeapOptions.html +0 -168
  251. package/docs/types/IdObject.html +0 -157
  252. package/docs/types/KeyValObject.html +0 -152
  253. package/docs/types/NavigatorParams.html +0 -181
  254. package/docs/types/NodeOrPropertyName.html +0 -147
  255. package/docs/types/PriorityQueueComparator.html +0 -167
  256. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
  257. package/docs/types/PriorityQueueOptions.html +0 -161
  258. package/docs/types/RBTreeOptions.html +0 -150
  259. package/docs/types/RecursiveAVLTreeNode.html +0 -152
  260. package/docs/types/RecursiveBSTNode.html +0 -152
  261. package/docs/types/RecursiveBinaryTreeNode.html +0 -152
  262. package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
  263. package/docs/types/SegmentTreeNodeVal.html +0 -147
  264. package/docs/types/TopologicalStatus.html +0 -147
  265. package/docs/types/TreeMultiSetOptions.html +0 -152
  266. package/docs/types/Turning.html +0 -147
  267. package/docs/types/VertexId.html +0 -147
  268. package/notes/bst.test.ts +0 -181
  269. package/notes/note.md +0 -34
@@ -39,21 +39,16 @@ var utils_1 = require("../../utils");
39
39
  var types_1 = require("../types");
40
40
  var AbstractBinaryTreeNode = /** @class */ (function () {
41
41
  /**
42
- * The constructor function initializes a BinaryTreeNode object with an id, value, and count.
42
+ * The constructor function initializes a BinaryTreeNode object with an id and an optional value.
43
43
  * @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
44
- * for the binary tree node.
45
- * @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value of the binary
46
- * tree node. If no value is provided, it will be `undefined`.
47
- * @param {number} [count] - The `count` parameter is an optional parameter that represents the number of times the
48
- * value `val` appears in the binary tree node. If the `count` parameter is not provided, it defaults to 1.
44
+ * of the binary tree node. It is used to distinguish one node from another in the binary tree.
45
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value that will be
46
+ * stored in the binary tree node. If no value is provided, it will be set to undefined.
49
47
  */
50
- function AbstractBinaryTreeNode(id, val, count) {
51
- this._familyPosition = types_1.FamilyPosition.ROOT;
52
- this._count = 1;
48
+ function AbstractBinaryTreeNode(id, val) {
53
49
  this._height = 0;
54
50
  this._id = id;
55
51
  this._val = val;
56
- this._count = count !== null && count !== void 0 ? count : 1;
57
52
  }
58
53
  Object.defineProperty(AbstractBinaryTreeNode.prototype, "id", {
59
54
  get: function () {
@@ -82,7 +77,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
82
77
  set: function (v) {
83
78
  if (v) {
84
79
  v.parent = this;
85
- v.familyPosition = types_1.FamilyPosition.LEFT;
86
80
  }
87
81
  this._left = v;
88
82
  },
@@ -96,7 +90,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
96
90
  set: function (v) {
97
91
  if (v) {
98
92
  v.parent = this;
99
- v.familyPosition = types_1.FamilyPosition.RIGHT;
100
93
  }
101
94
  this._right = v;
102
95
  },
@@ -113,67 +106,56 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
113
106
  enumerable: false,
114
107
  configurable: true
115
108
  });
116
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "familyPosition", {
117
- get: function () {
118
- return this._familyPosition;
119
- },
120
- set: function (v) {
121
- this._familyPosition = v;
122
- },
123
- enumerable: false,
124
- configurable: true
125
- });
126
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "count", {
109
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "height", {
127
110
  get: function () {
128
- return this._count;
111
+ return this._height;
129
112
  },
130
113
  set: function (v) {
131
- this._count = v;
114
+ this._height = v;
132
115
  },
133
116
  enumerable: false,
134
117
  configurable: true
135
118
  });
136
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "height", {
119
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "familyPosition", {
120
+ /**
121
+ * The function determines the position of a node in a family tree structure.
122
+ * @returns a value of type `FamilyPosition`.
123
+ */
137
124
  get: function () {
138
- return this._height;
139
- },
140
- set: function (v) {
141
- this._height = v;
125
+ var that = this;
126
+ if (that.parent) {
127
+ if (that.parent.left === that) {
128
+ if (that.left || that.right) {
129
+ return types_1.FamilyPosition.ROOT_LEFT;
130
+ }
131
+ else {
132
+ return types_1.FamilyPosition.LEFT;
133
+ }
134
+ }
135
+ else if (that.parent.right === that) {
136
+ if (that.left || that.right) {
137
+ return types_1.FamilyPosition.ROOT_RIGHT;
138
+ }
139
+ else {
140
+ return types_1.FamilyPosition.RIGHT;
141
+ }
142
+ }
143
+ else {
144
+ return types_1.FamilyPosition.MAL_NODE;
145
+ }
146
+ }
147
+ else {
148
+ if (that.left || that.right) {
149
+ return types_1.FamilyPosition.ROOT;
150
+ }
151
+ else {
152
+ return types_1.FamilyPosition.ISOLATED;
153
+ }
154
+ }
142
155
  },
143
156
  enumerable: false,
144
157
  configurable: true
145
158
  });
146
- /**
147
- * The function swaps the location of two nodes in a binary tree.
148
- * @param {FAMILY} swapNode - The `swapNode` parameter is of type `FAMILY`, which represents a node in a family tree.
149
- * @returns the `swapNode` object after swapping its properties with the properties of `this` object.
150
- */
151
- AbstractBinaryTreeNode.prototype.swapLocation = function (swapNode) {
152
- var val = swapNode.val, count = swapNode.count, height = swapNode.height;
153
- var tempNode = this.createNode(swapNode.id, val);
154
- if (tempNode instanceof AbstractBinaryTreeNode) {
155
- tempNode.val = val;
156
- tempNode.count = count;
157
- tempNode.height = height;
158
- swapNode.id = this.id;
159
- swapNode.val = this.val;
160
- swapNode.count = this.count;
161
- swapNode.height = this.height;
162
- this.id = tempNode.id;
163
- this.val = tempNode.val;
164
- this.count = tempNode.count;
165
- this.height = tempNode.height;
166
- }
167
- return swapNode;
168
- };
169
- /**
170
- * The `clone` function returns a new instance of the `FAMILY` class with the same `id`, `val`, and `count` properties.
171
- * @returns The `clone()` method is returning a new instance of the `FAMILY` class with the same `id`, `val`, and
172
- * `count` values as the current instance.
173
- */
174
- AbstractBinaryTreeNode.prototype.clone = function () {
175
- return this.createNode(this.id, this.val, this.count);
176
- };
177
159
  return AbstractBinaryTreeNode;
178
160
  }());
179
161
  exports.AbstractBinaryTreeNode = AbstractBinaryTreeNode;
@@ -184,116 +166,132 @@ var AbstractBinaryTree = /** @class */ (function () {
184
166
  * tree.
185
167
  */
186
168
  function AbstractBinaryTree(options) {
169
+ this._root = null;
170
+ this._size = 0;
187
171
  this._loopType = types_1.LoopType.ITERATIVE;
172
+ this._autoIncrementId = false;
173
+ this._maxId = -1;
174
+ // TODO this variable may be moved to TreeMultiset
175
+ this._isMergeDuplicatedVal = true;
188
176
  this._visitedId = [];
189
177
  this._visitedVal = [];
190
178
  this._visitedNode = [];
191
179
  this._visitedCount = [];
192
180
  this._visitedLeftSum = [];
193
- this._autoIncrementId = false;
194
- this._maxId = -1;
195
- this._isDuplicatedVal = false;
196
- this._root = null;
197
- this._size = 0;
198
- this._count = 0;
199
181
  if (options !== undefined) {
200
- var _a = options.loopType, loopType = _a === void 0 ? types_1.LoopType.ITERATIVE : _a, _b = options.autoIncrementId, autoIncrementId = _b === void 0 ? false : _b, _c = options.isDuplicatedVal, isDuplicatedVal = _c === void 0 ? false : _c;
201
- this._isDuplicatedVal = isDuplicatedVal;
182
+ var _a = options.loopType, loopType = _a === void 0 ? types_1.LoopType.ITERATIVE : _a, _b = options.autoIncrementId, autoIncrementId = _b === void 0 ? false : _b, _c = options.isMergeDuplicatedVal, isMergeDuplicatedVal = _c === void 0 ? true : _c;
183
+ this._isMergeDuplicatedVal = isMergeDuplicatedVal;
202
184
  this._autoIncrementId = autoIncrementId;
203
185
  this._loopType = loopType;
204
186
  }
205
187
  }
206
- Object.defineProperty(AbstractBinaryTree.prototype, "loopType", {
207
- get: function () {
208
- return this._loopType;
209
- },
210
- enumerable: false,
211
- configurable: true
212
- });
213
- Object.defineProperty(AbstractBinaryTree.prototype, "visitedId", {
188
+ Object.defineProperty(AbstractBinaryTree.prototype, "root", {
214
189
  get: function () {
215
- return this._visitedId;
190
+ return this._root;
216
191
  },
217
192
  enumerable: false,
218
193
  configurable: true
219
194
  });
220
- Object.defineProperty(AbstractBinaryTree.prototype, "visitedVal", {
195
+ Object.defineProperty(AbstractBinaryTree.prototype, "size", {
221
196
  get: function () {
222
- return this._visitedVal;
197
+ return this._size;
223
198
  },
224
199
  enumerable: false,
225
200
  configurable: true
226
201
  });
227
- Object.defineProperty(AbstractBinaryTree.prototype, "visitedNode", {
202
+ Object.defineProperty(AbstractBinaryTree.prototype, "loopType", {
228
203
  get: function () {
229
- return this._visitedNode;
204
+ return this._loopType;
230
205
  },
231
206
  enumerable: false,
232
207
  configurable: true
233
208
  });
234
- Object.defineProperty(AbstractBinaryTree.prototype, "visitedCount", {
209
+ Object.defineProperty(AbstractBinaryTree.prototype, "autoIncrementId", {
235
210
  get: function () {
236
- return this._visitedCount;
211
+ return this._autoIncrementId;
237
212
  },
238
213
  enumerable: false,
239
214
  configurable: true
240
215
  });
241
- Object.defineProperty(AbstractBinaryTree.prototype, "visitedLeftSum", {
216
+ Object.defineProperty(AbstractBinaryTree.prototype, "maxId", {
242
217
  get: function () {
243
- return this._visitedLeftSum;
218
+ return this._maxId;
244
219
  },
245
220
  enumerable: false,
246
221
  configurable: true
247
222
  });
248
- Object.defineProperty(AbstractBinaryTree.prototype, "autoIncrementId", {
223
+ Object.defineProperty(AbstractBinaryTree.prototype, "isMergeDuplicatedVal", {
249
224
  get: function () {
250
- return this._autoIncrementId;
225
+ return this._isMergeDuplicatedVal;
251
226
  },
252
227
  enumerable: false,
253
228
  configurable: true
254
229
  });
255
- Object.defineProperty(AbstractBinaryTree.prototype, "maxId", {
230
+ Object.defineProperty(AbstractBinaryTree.prototype, "visitedId", {
256
231
  get: function () {
257
- return this._maxId;
232
+ return this._visitedId;
258
233
  },
259
234
  enumerable: false,
260
235
  configurable: true
261
236
  });
262
- Object.defineProperty(AbstractBinaryTree.prototype, "isDuplicatedVal", {
237
+ Object.defineProperty(AbstractBinaryTree.prototype, "visitedVal", {
263
238
  get: function () {
264
- return this._isDuplicatedVal;
239
+ return this._visitedVal;
265
240
  },
266
241
  enumerable: false,
267
242
  configurable: true
268
243
  });
269
- Object.defineProperty(AbstractBinaryTree.prototype, "root", {
244
+ Object.defineProperty(AbstractBinaryTree.prototype, "visitedNode", {
270
245
  get: function () {
271
- return this._root;
246
+ return this._visitedNode;
272
247
  },
273
248
  enumerable: false,
274
249
  configurable: true
275
250
  });
276
- Object.defineProperty(AbstractBinaryTree.prototype, "size", {
251
+ Object.defineProperty(AbstractBinaryTree.prototype, "visitedCount", {
277
252
  get: function () {
278
- return this._size;
253
+ return this._visitedCount;
279
254
  },
280
255
  enumerable: false,
281
256
  configurable: true
282
257
  });
283
- Object.defineProperty(AbstractBinaryTree.prototype, "count", {
258
+ Object.defineProperty(AbstractBinaryTree.prototype, "visitedLeftSum", {
284
259
  get: function () {
285
- return this._count;
260
+ return this._visitedLeftSum;
286
261
  },
287
262
  enumerable: false,
288
263
  configurable: true
289
264
  });
290
265
  /**
291
- * The clear function resets the state of an object by setting its properties to their initial values.
266
+ * The `swapLocation` function swaps the location of two nodes in a binary tree.
267
+ * @param {N} srcNode - The source node that you want to swap with the destination node.
268
+ * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
269
+ * be swapped to.
270
+ * @returns The `destNode` is being returned.
271
+ */
272
+ AbstractBinaryTree.prototype.swapLocation = function (srcNode, destNode) {
273
+ var val = destNode.val, height = destNode.height, id = destNode.id;
274
+ var tempNode = this.createNode(id, val);
275
+ if (tempNode) {
276
+ tempNode.height = height;
277
+ if (tempNode instanceof AbstractBinaryTreeNode) {
278
+ // TODO should we consider the left, right children?
279
+ destNode.id = srcNode.id;
280
+ destNode.val = srcNode.val;
281
+ destNode.height = srcNode.height;
282
+ srcNode.id = tempNode.id;
283
+ srcNode.val = tempNode.val;
284
+ srcNode.height = tempNode.height;
285
+ }
286
+ }
287
+ return destNode;
288
+ };
289
+ /**
290
+ * The clear() function resets the root, size, and maxId properties to their initial values.
292
291
  */
293
292
  AbstractBinaryTree.prototype.clear = function () {
294
293
  this._setRoot(null);
295
294
  this._setSize(0);
296
- this._setCount(0);
297
295
  this._setMaxId(-1);
298
296
  };
299
297
  /**
@@ -304,19 +302,16 @@ var AbstractBinaryTree = /** @class */ (function () {
304
302
  return this.size === 0;
305
303
  };
306
304
  /**
307
- * The `add` function inserts a new node with a given ID and value into a binary tree, updating the count if the node
308
- * already exists.
309
- * @param {BinaryTreeNodeId} id - The id parameter is the identifier of the binary tree node. It is used to uniquely
310
- * identify each node in the binary tree.
311
- * @param {N} val - The value to be inserted into the binary tree.
312
- * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
313
- * value should be inserted into the binary tree. If not provided, it defaults to 1.
314
- * @returns The function `add` returns a `N` object if a new node is inserted, or `null` if no new node
315
- * is inserted, or `undefined` if the insertion fails.
305
+ * The `add` function adds a new node to a binary tree, updating the value of an existing node if it already exists.
306
+ * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
307
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. If no value is
308
+ * provided, the default value will be the same as the `id` parameter.
309
+ * @param {number} [count] - The `count` parameter is an optional number that represents the number of times the value
310
+ * should be added to the binary tree. If not provided, the default value is `undefined`.
311
+ * @returns The function `add` returns either a `BinaryTreeNode` object (`N`), `null`, or `undefined`.
316
312
  */
317
313
  AbstractBinaryTree.prototype.add = function (id, val, count) {
318
314
  var _this = this;
319
- count = count !== null && count !== void 0 ? count : 1;
320
315
  var _bfs = function (root, newNode) {
321
316
  var queue = [root];
322
317
  while (queue.length > 0) {
@@ -336,14 +331,12 @@ var AbstractBinaryTree = /** @class */ (function () {
336
331
  return;
337
332
  };
338
333
  var inserted;
339
- var needInsert = val !== null ? this.createNode(id, val !== null && val !== void 0 ? val : id, count) : null;
334
+ var needInsert = val !== null ? this.createNode(id, val) : null;
340
335
  var existNode = val !== null ? this.get(id, 'id') : null;
341
336
  if (this.root) {
342
337
  if (existNode) {
343
- existNode.count += count;
344
338
  existNode.val = val !== null && val !== void 0 ? val : id;
345
339
  if (needInsert !== null) {
346
- this._setCount(this.count + count);
347
340
  inserted = existNode;
348
341
  }
349
342
  }
@@ -352,48 +345,42 @@ var AbstractBinaryTree = /** @class */ (function () {
352
345
  }
353
346
  }
354
347
  else {
355
- this._setRoot(val !== null ? this.createNode(id, val !== null && val !== void 0 ? val : id, count) : null);
348
+ this._setRoot(val !== null ? this.createNode(id, val) : null);
356
349
  if (needInsert !== null) {
357
350
  this._setSize(1);
358
- this._setCount(count);
359
351
  }
360
352
  inserted = this.root;
361
353
  }
362
354
  return inserted;
363
355
  };
364
356
  /**
365
- * The function adds a new node to a binary tree as the left or right child of a given parent node.
357
+ * The function adds a new node to the left or right child of a parent node, updating the size of the tree if
358
+ * necessary.
366
359
  * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
367
360
  * either a node object (`N`) or `null`.
368
361
  * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
369
362
  * child.
370
- * @returns either the left or right child node that was added to the parent node. It can also return `null` or
371
- * `undefined` in certain cases.
363
+ * @returns either the left child node, the right child node, or undefined.
372
364
  */
373
365
  AbstractBinaryTree.prototype.addTo = function (newNode, parent) {
374
- var _a, _b;
375
366
  if (parent) {
376
367
  if (parent.left === undefined) {
377
368
  if (newNode) {
378
369
  newNode.parent = parent;
379
- newNode.familyPosition = types_1.FamilyPosition.LEFT;
380
370
  }
381
371
  parent.left = newNode;
382
372
  if (newNode !== null) {
383
373
  this._setSize(this.size + 1);
384
- this._setCount((_a = this.count + newNode.count) !== null && _a !== void 0 ? _a : 0);
385
374
  }
386
375
  return parent.left;
387
376
  }
388
377
  else if (parent.right === undefined) {
389
378
  if (newNode) {
390
379
  newNode.parent = parent;
391
- newNode.familyPosition = types_1.FamilyPosition.RIGHT;
392
380
  }
393
381
  parent.right = newNode;
394
382
  if (newNode !== null) {
395
383
  this._setSize(this.size + 1);
396
- this._setCount((_b = this.count + newNode.count) !== null && _b !== void 0 ? _b : 0);
397
384
  }
398
385
  return parent.right;
399
386
  }
@@ -406,22 +393,23 @@ var AbstractBinaryTree = /** @class */ (function () {
406
393
  }
407
394
  };
408
395
  /**
409
- * The `addMany` function inserts multiple items into a binary tree and returns an array of the inserted nodes or
396
+ * The `addMany` function adds multiple nodes to a binary tree and returns an array of the inserted nodes or
410
397
  * null/undefined values.
411
- * @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
412
- * array of `N` objects.
413
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
398
+ * @param {N[] | Array<N['val']>} data - The `data` parameter can be either an array of `N` objects or an array of
399
+ * `N['val']` values.
400
+ * @returns The function `addMany` returns an array of values of type `N | null | undefined`.
414
401
  */
415
402
  AbstractBinaryTree.prototype.addMany = function (data) {
416
403
  var e_1, _a, e_2, _b;
417
404
  var _c;
405
+ // TODO not sure addMany not be run multi times
418
406
  var inserted = [];
419
407
  var map = new Map();
420
- if (!this._isDuplicatedVal) {
408
+ if (this.isMergeDuplicatedVal) {
421
409
  try {
422
410
  for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
423
- var i = data_1_1.value;
424
- map.set(i, ((_c = map.get(i)) !== null && _c !== void 0 ? _c : 0) + 1);
411
+ var nodeOrId = data_1_1.value;
412
+ map.set(nodeOrId, ((_c = map.get(nodeOrId)) !== null && _c !== void 0 ? _c : 0) + 1);
425
413
  }
426
414
  }
427
415
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -434,53 +422,49 @@ var AbstractBinaryTree = /** @class */ (function () {
434
422
  }
435
423
  try {
436
424
  for (var data_2 = __values(data), data_2_1 = data_2.next(); !data_2_1.done; data_2_1 = data_2.next()) {
437
- var item = data_2_1.value;
425
+ var nodeOrId = data_2_1.value;
426
+ if (nodeOrId instanceof AbstractBinaryTreeNode) {
427
+ inserted.push(this.add(nodeOrId.id, nodeOrId.val));
428
+ continue;
429
+ }
430
+ if (nodeOrId === null) {
431
+ inserted.push(this.add(NaN, null, 0));
432
+ continue;
433
+ }
438
434
  // TODO will this cause an issue?
439
- var count = this._isDuplicatedVal ? 1 : map.get(item);
440
- if (item instanceof AbstractBinaryTreeNode) {
441
- inserted.push(this.add(item.id, item.val, item.count));
435
+ var count = this.isMergeDuplicatedVal ? map.get(nodeOrId) : 1;
436
+ var newId = void 0;
437
+ if (typeof nodeOrId === 'number') {
438
+ newId = this.autoIncrementId ? this.maxId + 1 : nodeOrId;
442
439
  }
443
- else if (typeof item === 'number') {
444
- if (!this._autoIncrementId) {
445
- if (!this._isDuplicatedVal) {
446
- if (map.get(item) !== undefined) {
447
- inserted.push(this.add(item, item, count));
448
- map.delete(item);
449
- }
440
+ else if (nodeOrId instanceof Object) {
441
+ if (this.autoIncrementId) {
442
+ newId = this.maxId + 1;
443
+ }
444
+ else {
445
+ if (Object.keys(nodeOrId).includes('id')) {
446
+ newId = nodeOrId.id;
450
447
  }
451
448
  else {
452
- inserted.push(this.add(item, item, 1));
449
+ console.warn(nodeOrId, 'Object value must has an id property when the autoIncrementId is false');
450
+ continue;
453
451
  }
454
452
  }
455
453
  }
456
- else if (item instanceof Object) {
457
- if (!this._isDuplicatedVal) {
458
- if (map.has(item)) {
459
- var newId = void 0;
460
- if (!this._autoIncrementId) {
461
- if (Object.keys(item).includes('id')) {
462
- newId = item.id;
463
- }
464
- else {
465
- console.warn('Object value must has an id property when the autoIncrementId is false');
466
- break;
467
- }
468
- }
469
- else {
470
- newId = this.maxId + 1;
471
- this._setMaxId(newId);
472
- }
473
- inserted.push(this.add(newId, item, count));
474
- map.delete(item);
475
- }
476
- }
477
- else {
478
- inserted.push(this.add(++this._maxId, item, 1));
454
+ else {
455
+ console.warn(nodeOrId, " is not added");
456
+ continue;
457
+ }
458
+ if (this.isMergeDuplicatedVal) {
459
+ if (map.has(nodeOrId)) {
460
+ inserted.push(this.add(newId, nodeOrId, count));
461
+ map.delete(nodeOrId);
479
462
  }
480
463
  }
481
- else if (item === null) {
482
- inserted.push(this.add(Number.MAX_SAFE_INTEGER, item, 0));
464
+ else {
465
+ inserted.push(this.add(newId, nodeOrId, 1));
483
466
  }
467
+ this._setMaxId(newId);
484
468
  }
485
469
  }
486
470
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -493,87 +477,95 @@ var AbstractBinaryTree = /** @class */ (function () {
493
477
  return inserted;
494
478
  };
495
479
  /**
496
- * The `fill` function clears the current data and inserts new data, returning a boolean indicating if the insertion
497
- * was successful.
498
- * @param {N[] | N[]} data - The `data` parameter can be either an array of elements of type `N` or an
499
- * array of `N` objects.
500
- * @returns The method is returning a boolean value.
480
+ * The `fill` function clears the current data and adds new data, returning a boolean indicating if the operation was
481
+ * successful.
482
+ * @param {N[] | Array<N['val']>} data - The `data` parameter can be either an array of objects or an array of arrays.
483
+ * Each object or array should have a property called `val`.
484
+ * @returns a boolean value.
501
485
  */
502
486
  AbstractBinaryTree.prototype.fill = function (data) {
503
487
  this.clear();
504
488
  return data.length === this.addMany(data).length;
505
489
  };
506
490
  /**
507
- * The function removes a node from a binary tree and returns information about the deleted node.
508
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to remove.
509
- * It is of type `BinaryTreeNodeId`.
491
+ * The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
492
+ * node that needs to be balanced.
493
+ * @param {N | BinaryTreeNodeId} nodeOrId - The `nodeOrId` parameter can be either a node object (`N`) or a binary tree
494
+ * node ID (`BinaryTreeNodeId`).
510
495
  * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
511
- * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
512
- * not be decremented and the overall count of the binary tree will not be updated. If `
513
- * @returns An array of objects is being returned. Each object in the array has two properties: "deleted" and
514
- * "needBalanced". The "deleted" property contains the deleted node or undefined if no node was deleted. The
515
- * "needBalanced" property is always null.
496
+ * whether to ignore the count of the nodes in the binary tree. If `ignoreCount` is set to `true`, the count of the
497
+ * nodes in the binary tree will not be updated after removing a node. If `ignoreCount`
498
+ * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
516
499
  */
517
- AbstractBinaryTree.prototype.remove = function (id, ignoreCount) {
518
- var nodes = this.getNodes(id, 'id', true);
519
- var node = nodes[0];
520
- if (!node)
521
- node = undefined;
522
- else if (node.count > 1 && !ignoreCount) {
523
- node.count--;
524
- this._setCount(this.count - 1);
500
+ AbstractBinaryTree.prototype.remove = function (nodeOrId, ignoreCount) {
501
+ var bstDeletedResult = [];
502
+ if (!this.root)
503
+ return bstDeletedResult;
504
+ var curr = (typeof nodeOrId === 'number') ? this.get(nodeOrId) : nodeOrId;
505
+ if (!curr)
506
+ return bstDeletedResult;
507
+ var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
508
+ var needBalanced = null, orgCurrent = curr;
509
+ if (!curr.left) {
510
+ if (!parent) {
511
+ if (curr.right !== undefined)
512
+ this._setRoot(curr.right);
513
+ }
514
+ else {
515
+ var fp = curr.familyPosition;
516
+ if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
517
+ parent.left = curr.right;
518
+ }
519
+ else if (fp === types_1.FamilyPosition.RIGHT || fp === types_1.FamilyPosition.ROOT_RIGHT) {
520
+ parent.right = curr.right;
521
+ }
522
+ needBalanced = parent;
523
+ }
525
524
  }
526
- else if (node instanceof AbstractBinaryTreeNode) {
527
- var _a = __read(this.getSubTreeSizeAndCount(node), 2), subSize = _a[0], subCount = _a[1];
528
- switch (node.familyPosition) {
529
- case 0:
530
- this._setSize(this.size - subSize);
531
- this._setCount(this.count - subCount);
532
- node = undefined;
533
- break;
534
- case 1:
535
- if (node.parent) {
536
- this._setSize(this.size - subSize);
537
- this._setCount(this.count - subCount);
538
- node.parent.left = null;
539
- }
540
- break;
541
- case 2:
542
- if (node.parent) {
543
- this._setSize(this.size - subSize);
544
- this._setCount(this.count - subCount);
545
- node.parent.right = null;
546
- }
547
- break;
525
+ else {
526
+ var leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
527
+ if (leftSubTreeRightMost) {
528
+ var parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
529
+ orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
530
+ if (parentOfLeftSubTreeMax) {
531
+ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
532
+ parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
533
+ else
534
+ parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
535
+ needBalanced = parentOfLeftSubTreeMax;
536
+ }
548
537
  }
549
538
  }
550
- return [{ deleted: node, needBalanced: null }];
539
+ this._setSize(this.size - 1);
540
+ bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
541
+ return bstDeletedResult;
551
542
  };
552
543
  /**
553
- * The function calculates the depth of a binary tree node by traversing its parent nodes.
554
- * @param node - N - This is the node for which we want to calculate the depth. It is a generic type,
555
- * meaning it can represent any type of data that we want to store in the node.
556
- * @returns The depth of the given binary tree node.
544
+ * The function calculates the depth of a node in a binary tree.
545
+ * @param {N | BinaryTreeNodeId | null} beginRoot - The `beginRoot` parameter can be one of the following:
546
+ * @returns the depth of the given node or binary tree.
557
547
  */
558
- AbstractBinaryTree.prototype.getDepth = function (node) {
548
+ AbstractBinaryTree.prototype.getDepth = function (beginRoot) {
549
+ if (typeof beginRoot === 'number')
550
+ beginRoot = this.get(beginRoot, 'id');
559
551
  var depth = 0;
560
- while (node.parent) {
552
+ while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {
561
553
  depth++;
562
- node = node.parent;
554
+ beginRoot = beginRoot.parent;
563
555
  }
564
556
  return depth;
565
557
  };
566
558
  /**
567
- * The `getHeight` function calculates the maximum height of a binary tree using either a recursive or iterative
568
- * approach.
569
- * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
570
- * `N | null`. It represents the starting node from which to calculate the height of the binary tree.
571
- * If no value is provided for `beginRoot`, the function will use the `root` property of the class instance as
559
+ * The `getHeight` function calculates the maximum height of a binary tree, either recursively or iteratively.
560
+ * @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
561
+ * generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
562
+ * node), or `null`.
572
563
  * @returns the height of the binary tree.
573
564
  */
574
565
  AbstractBinaryTree.prototype.getHeight = function (beginRoot) {
575
- var _a, _b, _c;
576
566
  beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
567
+ if (typeof beginRoot === 'number')
568
+ beginRoot = this.get(beginRoot, 'id');
577
569
  if (!beginRoot)
578
570
  return -1;
579
571
  if (this._loopType === types_1.LoopType.RECURSIVE) {
@@ -587,39 +579,30 @@ var AbstractBinaryTree = /** @class */ (function () {
587
579
  return _getMaxHeight_1(beginRoot);
588
580
  }
589
581
  else {
590
- var stack = [];
591
- var node = beginRoot, last = null;
592
- var depths = new Map();
593
- while (stack.length > 0 || node) {
594
- if (node) {
595
- stack.push(node);
596
- node = node.left;
582
+ if (!beginRoot) {
583
+ return -1;
584
+ }
585
+ var stack = [{ node: beginRoot, depth: 0 }];
586
+ var maxHeight = 0;
587
+ while (stack.length > 0) {
588
+ var _a = stack.pop(), node = _a.node, depth = _a.depth;
589
+ if (node.left) {
590
+ stack.push({ node: node.left, depth: depth + 1 });
597
591
  }
598
- else {
599
- node = stack[stack.length - 1];
600
- if (!node.right || last === node.right) {
601
- node = stack.pop();
602
- if (node) {
603
- var leftHeight = node.left ? (_a = depths.get(node.left)) !== null && _a !== void 0 ? _a : -1 : -1;
604
- var rightHeight = node.right ? (_b = depths.get(node.right)) !== null && _b !== void 0 ? _b : -1 : -1;
605
- depths.set(node, 1 + Math.max(leftHeight, rightHeight));
606
- last = node;
607
- node = null;
608
- }
609
- }
610
- else
611
- node = node.right;
592
+ if (node.right) {
593
+ stack.push({ node: node.right, depth: depth + 1 });
612
594
  }
595
+ maxHeight = Math.max(maxHeight, depth);
613
596
  }
614
- return (_c = depths.get(beginRoot)) !== null && _c !== void 0 ? _c : -1;
597
+ return maxHeight;
615
598
  }
616
599
  };
617
600
  /**
618
601
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a recursive or iterative
619
602
  * approach.
620
- * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type
621
- * `N | null`. It represents the starting node from which to calculate the minimum height of the binary
622
- * tree. If no value is provided for `beginRoot`, the function will use the root node of the binary tree.
603
+ * @param {N | null} [beginRoot] - The `beginRoot` parameter is an optional parameter of type `N` or `null`. It
604
+ * represents the starting node from which to calculate the minimum height of a binary tree. If no value is provided
605
+ * for `beginRoot`, the `this.root` property is used as the default value.
623
606
  * @returns The function `getMinHeight` returns the minimum height of the binary tree.
624
607
  */
625
608
  AbstractBinaryTree.prototype.getMinHeight = function (beginRoot) {
@@ -668,25 +651,25 @@ var AbstractBinaryTree = /** @class */ (function () {
668
651
  }
669
652
  };
670
653
  /**
671
- * The function checks if a binary tree is balanced by comparing the minimum height and the maximum height of the tree.
672
- * @param {N | null} [beginRoot] - The `beginRoot` parameter is the root node of a binary tree. It is
673
- * of type `N | null`, which means it can either be a `BinaryTreeNode` object or `null`.
654
+ * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the height of the
655
+ * tree.
656
+ * @param {N | null} [beginRoot] - The parameter `beginRoot` is of type `N` or `null`. It represents the root node of a
657
+ * tree or null if the tree is empty.
674
658
  * @returns The method is returning a boolean value.
675
659
  */
676
- AbstractBinaryTree.prototype.isBalanced = function (beginRoot) {
660
+ AbstractBinaryTree.prototype.isPerfectlyBalanced = function (beginRoot) {
677
661
  return (this.getMinHeight(beginRoot) + 1 >= this.getHeight(beginRoot));
678
662
  };
679
663
  /**
680
- * The function `getNodes` returns an array of binary tree nodes that match a given property value, with options for
681
- * searching recursively or iteratively.
664
+ * The function `getNodes` returns an array of nodes that match a given property name and value in a binary tree.
682
665
  * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
683
666
  * generic type `N`. It represents the property of the binary tree node that you want to search for.
684
667
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
685
668
  * specifies the property name to use when searching for nodes. If not provided, it defaults to 'id'.
686
669
  * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
687
- * return only one node that matches the `nodeProperty` or `propertyName` criteria. If `onlyOne` is set to `true`, the
688
- * function will stop traversing the tree and return the first matching node. If `
689
- * @returns The function `getNodes` returns an array of `N | null | undefined` objects.
670
+ * return only one node that matches the given `nodeProperty` or `propertyName`. If `onlyOne` is set to `true`, the
671
+ * function will stop traversing the tree and return the first matching node. If `only
672
+ * @returns an array of nodes (type N).
690
673
  */
691
674
  AbstractBinaryTree.prototype.getNodes = function (nodeProperty, propertyName, onlyOne) {
692
675
  var _this = this;
@@ -694,7 +677,7 @@ var AbstractBinaryTree = /** @class */ (function () {
694
677
  return [];
695
678
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
696
679
  var result = [];
697
- if (this._loopType === types_1.LoopType.RECURSIVE) {
680
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
698
681
  var _traverse_1 = function (cur) {
699
682
  if (_this._pushByPropertyNameStopOrNot(cur, result, nodeProperty, propertyName, onlyOne))
700
683
  return;
@@ -720,25 +703,27 @@ var AbstractBinaryTree = /** @class */ (function () {
720
703
  return result;
721
704
  };
722
705
  /**
723
- * The function checks if a binary tree node has a specific property or if any node in the tree has a specific
724
- * property.
725
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
726
- * generic type `N`. It represents the property of a binary tree node that you want to check.
706
+ * The function checks if a binary tree node has a specific property.
707
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
708
+ * It represents the property of the binary tree node that you want to check.
727
709
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
728
- * specifies the name of the property to check for in the nodes.
710
+ * specifies the name of the property to be checked in the nodes. If not provided, it defaults to 'id'.
729
711
  * @returns a boolean value.
730
712
  */
731
713
  AbstractBinaryTree.prototype.has = function (nodeProperty, propertyName) {
714
+ propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
732
715
  return this.getNodes(nodeProperty, propertyName).length > 0;
733
716
  };
734
717
  /**
735
- * The function returns the first binary tree node that matches the given property name and value, or null if no match
736
- * is found.
737
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
738
- * generic type `N`. It represents the property of the binary tree node that you want to search for.
718
+ * The function returns the first node that matches the given property name and value, or null if no matching node is
719
+ * found.
720
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or `N`.
721
+ * It represents the property of the binary tree node that you want to search for.
739
722
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
740
- * specifies the property of the binary tree node to search for. If not provided, it defaults to `'id'`.
741
- * @returns a BinaryTreeNode object or null.
723
+ * specifies the property name to be used for searching the binary tree nodes. If this parameter is not provided, the
724
+ * default value is set to `'id'`.
725
+ * @returns either the value of the specified property of the node, or the node itself if no property name is provided.
726
+ * If no matching node is found, it returns null.
742
727
  */
743
728
  AbstractBinaryTree.prototype.get = function (nodeProperty, propertyName) {
744
729
  var _a;
@@ -746,11 +731,10 @@ var AbstractBinaryTree = /** @class */ (function () {
746
731
  return (_a = this.getNodes(nodeProperty, propertyName, true)[0]) !== null && _a !== void 0 ? _a : null;
747
732
  };
748
733
  /**
749
- * The function getPathToRoot returns an array of BinaryTreeNode objects representing the path from a given node to the
750
- * root of a binary tree.
751
- * @param node - The `node` parameter is a BinaryTreeNode object.
752
- * @returns The function `getPathToRoot` returns an array of `N` objects, representing the path from
753
- * the given `node` to the root of the binary tree.
734
+ * The function getPathToRoot takes a node and returns an array of nodes representing the path from the given node to
735
+ * the root node.
736
+ * @param {N} node - The parameter `node` represents a node in a tree data structure.
737
+ * @returns The function `getPathToRoot` returns an array of nodes (`N[]`).
754
738
  */
755
739
  AbstractBinaryTree.prototype.getPathToRoot = function (node) {
756
740
  var result = [];
@@ -762,24 +746,28 @@ var AbstractBinaryTree = /** @class */ (function () {
762
746
  return result;
763
747
  };
764
748
  /**
765
- * The `getLeftMost` function returns the leftmost node in a binary tree, either recursively or iteratively using tail
766
- * recursion optimization.
767
- * @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
768
- * | null`. It represents the starting node from which to find the leftmost node in a binary tree. If no node is
769
- * provided, the function will use the root node of the binary tree.
770
- * @returns The `getLeftMost` function returns the leftmost node in a binary tree.
749
+ * The `getLeftMost` function returns the leftmost node in a binary tree, starting from a specified node or the root if
750
+ * no node is specified.
751
+ * @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
752
+ * generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
753
+ * node), or `null`.
754
+ * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
755
+ * provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the
756
+ * traversal from the root of the binary tree. If there are no nodes in the binary tree, it returns `null`.
771
757
  */
772
- AbstractBinaryTree.prototype.getLeftMost = function (node) {
773
- node = node !== null && node !== void 0 ? node : this.root;
774
- if (!node)
775
- return node;
758
+ AbstractBinaryTree.prototype.getLeftMost = function (beginRoot) {
759
+ if (typeof beginRoot === 'number')
760
+ beginRoot = this.get(beginRoot, 'id');
761
+ beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
762
+ if (!beginRoot)
763
+ return beginRoot;
776
764
  if (this._loopType === types_1.LoopType.RECURSIVE) {
777
765
  var _traverse_2 = function (cur) {
778
766
  if (!cur.left)
779
767
  return cur;
780
768
  return _traverse_2(cur.left);
781
769
  };
782
- return _traverse_2(node);
770
+ return _traverse_2(beginRoot);
783
771
  }
784
772
  else {
785
773
  // Indirect implementation of iteration using tail recursion optimization
@@ -788,16 +776,18 @@ var AbstractBinaryTree = /** @class */ (function () {
788
776
  return cur;
789
777
  return _traverse_3.cont(cur.left);
790
778
  });
791
- return _traverse_3(node);
779
+ return _traverse_3(beginRoot);
792
780
  }
793
781
  };
794
782
  /**
795
783
  * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or iteratively using
796
784
  * tail recursion optimization.
797
- * @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
798
- * | null`. It represents the starting node from which to find the rightmost node in a binary tree. If no node is
799
- * provided, the function will use the root node of the binary tree.
800
- * @returns The `getRightMost` function returns the rightmost node in a binary tree.
785
+ * @param {N | null} [node] - The `node` parameter is an optional parameter of type `N` or `null`. It represents the
786
+ * starting node from which we want to find the rightmost node. If no node is provided, the `node` parameter defaults
787
+ * to `this.root`, which is the root node of the data structure
788
+ * @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If the `node` parameter is
789
+ * not provided, it defaults to the root node of the tree. If the tree is empty or the `node` parameter is `null`, the
790
+ * function returns `null`.
801
791
  */
802
792
  AbstractBinaryTree.prototype.getRightMost = function (node) {
803
793
  node = node !== null && node !== void 0 ? node : this.root;
@@ -822,11 +812,12 @@ var AbstractBinaryTree = /** @class */ (function () {
822
812
  }
823
813
  };
824
814
  /**
825
- * The function `isBSTByRooted` checks if a binary tree is a binary search tree (BST) by rooted traversal.
815
+ * The function checks if a binary search tree is valid by traversing it either recursively or iteratively.
826
816
  * @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
827
817
  * @returns a boolean value.
828
818
  */
829
819
  AbstractBinaryTree.prototype.isBSTByRooted = function (node) {
820
+ // TODO there is a bug
830
821
  if (!node)
831
822
  return true;
832
823
  if (this._loopType === types_1.LoopType.RECURSIVE) {
@@ -866,52 +857,48 @@ var AbstractBinaryTree = /** @class */ (function () {
866
857
  return this.isBSTByRooted(this.root);
867
858
  };
868
859
  /**
869
- * The function calculates the size and count of a subtree in a binary tree using either recursive or iterative
870
- * traversal.
871
- * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter is the root node of a binary
872
- * tree.
873
- * @returns The function `getSubTreeSizeAndCount` returns an array `[number, number]`. The first element of the array
874
- * represents the size of the subtree, and the second element represents the count of the nodes in the subtree.
860
+ * The function calculates the size of a subtree by traversing it either recursively or iteratively.
861
+ * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
862
+ * binary tree.
863
+ * @returns the size of the subtree rooted at `subTreeRoot`.
875
864
  */
876
- AbstractBinaryTree.prototype.getSubTreeSizeAndCount = function (subTreeRoot) {
877
- var res = [0, 0];
865
+ AbstractBinaryTree.prototype.getSubTreeSize = function (subTreeRoot) {
866
+ var size = 0;
878
867
  if (!subTreeRoot)
879
- return res;
868
+ return size;
880
869
  if (this._loopType === types_1.LoopType.RECURSIVE) {
881
870
  var _traverse_6 = function (cur) {
882
- res[0]++;
883
- res[1] += cur.count;
871
+ size++;
884
872
  cur.left && _traverse_6(cur.left);
885
873
  cur.right && _traverse_6(cur.right);
886
874
  };
887
875
  _traverse_6(subTreeRoot);
888
- return res;
876
+ return size;
889
877
  }
890
878
  else {
891
879
  var stack = [subTreeRoot];
892
880
  while (stack.length > 0) {
893
881
  var cur = stack.pop();
894
- res[0]++;
895
- res[1] += cur.count;
882
+ size++;
896
883
  cur.right && stack.push(cur.right);
897
884
  cur.left && stack.push(cur.left);
898
885
  }
899
- return res;
886
+ return size;
900
887
  }
901
888
  };
902
- // --- start additional methods ---
903
889
  /**
904
- * The function `subTreeSum` calculates the sum of a specified property in a binary tree, either recursively or
905
- * iteratively.
906
- * @param subTreeRoot - The subTreeRoot parameter is the root node of the subtree for which you want to calculate the
907
- * sum.
908
- * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
909
- * specifies the property of the `BinaryTreeNode` object to use for calculating the sum. If `propertyName` is not
910
- * provided, it defaults to `'val'`.
911
- * @returns a number, which is the sum of the values of the nodes in the subtree rooted at `subTreeRoot`.
890
+ * The function `subTreeSum` calculates the sum of a specified property in a binary tree or subtree.
891
+ * @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
892
+ * tree or the ID of a binary tree node. It can also be `null` if there is no subtree.
893
+ * @param {BinaryTreeNodePropertyName} [propertyName] - propertyName is an optional parameter that specifies the
894
+ * property of the binary tree node to use for calculating the sum. It can be either 'id' or 'val'. If propertyName is
895
+ * not provided, it defaults to 'id'.
896
+ * @returns a number, which is the sum of the values of the specified property in the subtree rooted at `subTreeRoot`.
912
897
  */
913
898
  AbstractBinaryTree.prototype.subTreeSum = function (subTreeRoot, propertyName) {
914
899
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
900
+ if (typeof subTreeRoot === 'number')
901
+ subTreeRoot = this.get(subTreeRoot, 'id');
915
902
  if (!subTreeRoot)
916
903
  return 0;
917
904
  var sum = 0;
@@ -921,9 +908,6 @@ var AbstractBinaryTree = /** @class */ (function () {
921
908
  case 'id':
922
909
  needSum = cur.id;
923
910
  break;
924
- case 'count':
925
- needSum = cur.count;
926
- break;
927
911
  case 'val':
928
912
  needSum = typeof cur.val === 'number' ? cur.val : 0;
929
913
  break;
@@ -953,17 +937,19 @@ var AbstractBinaryTree = /** @class */ (function () {
953
937
  return sum;
954
938
  };
955
939
  /**
956
- * The function `subTreeAdd` adds a specified delta value to a property of each node in a binary tree.
957
- * @param subTreeRoot - The `subTreeRoot` parameter is the root node of the subtree where the values will be modified.
940
+ * The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
941
+ * @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
942
+ * tree or the ID of a node in the binary tree. It can also be `null` if there is no subtree to add to.
958
943
  * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
959
- * each node in the subtree should be increased or decreased.
944
+ * each node in the subtree should be incremented.
960
945
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
961
- * specifies the property of the `BinaryTreeNode` that should be modified. It defaults to `'id'` if not provided.
962
- * @returns a boolean value, which is `true`.
946
+ * specifies the property of the binary tree node that should be modified. If not provided, it defaults to 'id'.
947
+ * @returns a boolean value.
963
948
  */
964
949
  AbstractBinaryTree.prototype.subTreeAdd = function (subTreeRoot, delta, propertyName) {
965
- var _this = this;
966
950
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
951
+ if (typeof subTreeRoot === 'number')
952
+ subTreeRoot = this.get(subTreeRoot, 'id');
967
953
  if (!subTreeRoot)
968
954
  return false;
969
955
  var _addByProperty = function (cur) {
@@ -971,10 +957,6 @@ var AbstractBinaryTree = /** @class */ (function () {
971
957
  case 'id':
972
958
  cur.id += delta;
973
959
  break;
974
- case 'count':
975
- cur.count += delta;
976
- _this._setCount(_this.count + delta);
977
- break;
978
960
  default:
979
961
  cur.id += delta;
980
962
  break;
@@ -1000,13 +982,13 @@ var AbstractBinaryTree = /** @class */ (function () {
1000
982
  return true;
1001
983
  };
1002
984
  /**
1003
- * The BFS function performs a breadth-first search on a binary tree and returns the results based on a specified node
1004
- * or property name.
985
+ * The BFS function performs a breadth-first search on a binary tree, accumulating properties of each node based on a
986
+ * specified property name.
1005
987
  * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
1006
- * represents either a node or a property name. If a node is provided, the breadth-first search algorithm will be
1007
- * performed starting from that node. If a property name is provided, the breadth-first search algorithm will be
1008
- * performed starting from the root node
1009
- * @returns an object of type `AbstractBinaryTreeNodeProperties<N>`.
988
+ * represents either a node or a property name. If a node is provided, the breadth-first search (BFS) algorithm will be
989
+ * performed starting from that node. If a property name is provided, the BFS algorithm will be performed starting from
990
+ * the
991
+ * @returns an instance of the `AbstractBinaryTreeNodeProperties` class with generic type `N`.
1010
992
  */
1011
993
  AbstractBinaryTree.prototype.BFS = function (nodeOrPropertyName) {
1012
994
  nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
@@ -1025,16 +1007,15 @@ var AbstractBinaryTree = /** @class */ (function () {
1025
1007
  return this._getResultByPropertyName(nodeOrPropertyName);
1026
1008
  };
1027
1009
  /**
1028
- * The DFS function performs a depth-first search traversal on a binary tree and returns the results based on the
1029
- * specified pattern and node or property name.
1030
- * @param {'in' | 'pre' | 'post'} [pattern] - The "pattern" parameter is used to specify the order in which the nodes
1031
- * of a binary tree are traversed during the Depth-First Search (DFS) algorithm. It can take one of three values: 'in',
1032
- * 'pre', or 'post'.
1010
+ * The DFS function performs a depth-first search traversal on a binary tree and returns the accumulated properties of
1011
+ * each node based on the specified pattern and property name.
1012
+ * @param {'in' | 'pre' | 'post'} [pattern] - The "pattern" parameter is used to specify the traversal order of the
1013
+ * binary tree. It can have three possible values:
1033
1014
  * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is a string that represents
1034
- * either the name of a property in the `BinaryTreeNode` object or the value of the `id` property in the
1035
- * `BinaryTreeNode` object. This parameter is used to accumulate the results based on the specified property name. If
1036
- * no value
1037
- * @returns an object of type `AbstractBinaryTreeNodeProperties<N>`.
1015
+ * the name of a property of the nodes in the binary tree. This property will be used to accumulate values during the
1016
+ * depth-first search traversal. If no `nodeOrPropertyName` is provided, the default value is `'id'`.
1017
+ * @returns an instance of the AbstractBinaryTreeNodeProperties class, which contains the accumulated properties of the
1018
+ * binary tree nodes based on the specified pattern and node or property name.
1038
1019
  */
1039
1020
  AbstractBinaryTree.prototype.DFS = function (pattern, nodeOrPropertyName) {
1040
1021
  var _this = this;
@@ -1070,11 +1051,15 @@ var AbstractBinaryTree = /** @class */ (function () {
1070
1051
  return this._getResultByPropertyName(nodeOrPropertyName);
1071
1052
  };
1072
1053
  /**
1073
- * Time complexity is O(n)
1074
- * Space complexity of Iterative DFS equals to recursive DFS which is O(n) because of the stack
1075
- * @param pattern
1076
- * @param nodeOrPropertyName
1077
- * @constructor
1054
+ * The DFSIterative function performs an iterative depth-first search traversal on a binary tree, with the option to
1055
+ * specify the traversal pattern and the property name to accumulate results by.
1056
+ * @param {'in' | 'pre' | 'post'} [pattern] - The "pattern" parameter determines the order in which the nodes of the
1057
+ * binary tree are visited during the depth-first search. It can have one of the following values:
1058
+ * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is used to specify the
1059
+ * property of the nodes that you want to retrieve or perform operations on during the depth-first search traversal. By
1060
+ * default, it is set to `'id'`, which means that the traversal will accumulate results based on the `id` property of
1061
+ * the
1062
+ * @returns an object of type AbstractBinaryTreeNodeProperties<N>.
1078
1063
  */
1079
1064
  AbstractBinaryTree.prototype.DFSIterative = function (pattern, nodeOrPropertyName) {
1080
1065
  pattern = pattern || 'in';
@@ -1177,15 +1162,12 @@ var AbstractBinaryTree = /** @class */ (function () {
1177
1162
  case 'node':
1178
1163
  levelsNodes[level].push(node);
1179
1164
  break;
1180
- case 'count':
1181
- levelsNodes[level].push(node.count);
1182
- break;
1183
1165
  default:
1184
1166
  levelsNodes[level].push(node.id);
1185
1167
  break;
1186
1168
  }
1187
1169
  };
1188
- if (this._loopType === types_1.LoopType.RECURSIVE) {
1170
+ if (this.loopType === types_1.LoopType.RECURSIVE) {
1189
1171
  var _recursive_1 = function (node, level) {
1190
1172
  if (!levelsNodes[level])
1191
1173
  levelsNodes[level] = [];
@@ -1234,15 +1216,13 @@ var AbstractBinaryTree = /** @class */ (function () {
1234
1216
  };
1235
1217
  /**
1236
1218
  * The `morris` function performs an in-order, pre-order, or post-order traversal on a binary tree using the Morris
1237
- * traversal algorithm and returns the results based on the specified property name.
1238
- * The time complexity of Morris traversal is O(n), it's may slower than others
1239
- * The space complexity Morris traversal is O(1) because no using stack
1240
- * @param {'in' | 'pre' | 'post'} [pattern] - The `pattern` parameter is an optional parameter that determines the
1241
- * traversal pattern of the binary tree. It can have one of three values:
1219
+ * traversal algorithm.
1220
+ * @param {'in' | 'pre' | 'post'} [pattern] - The `pattern` parameter determines the traversal pattern for the binary
1221
+ * tree. It can have one of three values:
1242
1222
  * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is used to specify the
1243
- * property of the nodes that you want to retrieve in the results. It can be either the node itself or the name of the
1244
- * property. If not provided, it defaults to `'id'`.
1245
- * @returns The function `morris` returns an object of type `AbstractBinaryTreeNodeProperties<N>`.
1223
+ * property name of the nodes that you want to retrieve. It can be any valid property name of the nodes in the binary
1224
+ * tree.
1225
+ * @returns an array of AbstractBinaryTreeNodeProperties<N> objects.
1246
1226
  */
1247
1227
  AbstractBinaryTree.prototype.morris = function (pattern, nodeOrPropertyName) {
1248
1228
  var _this = this;
@@ -1331,71 +1311,114 @@ var AbstractBinaryTree = /** @class */ (function () {
1331
1311
  }
1332
1312
  return this._getResultByPropertyName(nodeOrPropertyName);
1333
1313
  };
1314
+ /**
1315
+ * The function sets the loop type for a protected variable.
1316
+ * @param {LoopType} value - The value parameter is of type LoopType.
1317
+ */
1334
1318
  AbstractBinaryTree.prototype._setLoopType = function (value) {
1335
1319
  this._loopType = value;
1336
1320
  };
1321
+ /**
1322
+ * The function sets the value of the `_visitedId` property in a protected manner.
1323
+ * @param {BinaryTreeNodeId[]} value - value is an array of BinaryTreeNodeId values.
1324
+ */
1337
1325
  AbstractBinaryTree.prototype._setVisitedId = function (value) {
1338
1326
  this._visitedId = value;
1339
1327
  };
1328
+ /**
1329
+ * The function sets the value of the "_visitedVal" property to the given array.
1330
+ * @param value - An array of type N.
1331
+ */
1340
1332
  AbstractBinaryTree.prototype._setVisitedVal = function (value) {
1341
1333
  this._visitedVal = value;
1342
1334
  };
1335
+ /**
1336
+ * The function sets the value of the _visitedNode property.
1337
+ * @param {N[]} value - N[] is an array of elements of type N.
1338
+ */
1343
1339
  AbstractBinaryTree.prototype._setVisitedNode = function (value) {
1344
1340
  this._visitedNode = value;
1345
1341
  };
1342
+ /**
1343
+ * The function sets the value of the visitedCount property.
1344
+ * @param {number[]} value - The value parameter is an array of numbers.
1345
+ */
1346
1346
  AbstractBinaryTree.prototype.setVisitedCount = function (value) {
1347
1347
  this._visitedCount = value;
1348
1348
  };
1349
+ /**
1350
+ * The function sets the value of the `_visitedLeftSum` property to the provided array.
1351
+ * @param {number[]} value - An array of numbers that represents the visited left sum.
1352
+ */
1349
1353
  AbstractBinaryTree.prototype._setVisitedLeftSum = function (value) {
1350
1354
  this._visitedLeftSum = value;
1351
1355
  };
1356
+ /**
1357
+ * The function sets the value of the _autoIncrementId property.
1358
+ * @param {boolean} value - The value parameter is a boolean that determines whether the id should be automatically
1359
+ * incremented or not. If value is true, the id will be automatically incremented. If value is false, the id will not
1360
+ * be automatically incremented.
1361
+ */
1352
1362
  AbstractBinaryTree.prototype._setAutoIncrementId = function (value) {
1353
1363
  this._autoIncrementId = value;
1354
1364
  };
1365
+ /**
1366
+ * The function sets the maximum ID value.
1367
+ * @param {number} value - The value parameter is a number that represents the new maximum ID value.
1368
+ */
1355
1369
  AbstractBinaryTree.prototype._setMaxId = function (value) {
1356
1370
  this._maxId = value;
1357
1371
  };
1372
+ /**
1373
+ * The function sets the value of a protected property called "_isMergeDuplicatedVal".
1374
+ * @param {boolean} value - The value parameter is a boolean value that determines whether the isMergeDuplicatedVal
1375
+ * property should be set to true or false.
1376
+ */
1358
1377
  AbstractBinaryTree.prototype._setIsDuplicatedVal = function (value) {
1359
- this._isDuplicatedVal = value;
1378
+ this._isMergeDuplicatedVal = value;
1360
1379
  };
1380
+ /**
1381
+ * The function sets the root property of an object to a given value, and if the value is not null, it also sets the
1382
+ * parent property of the value to undefined.
1383
+ * @param {N | null} v - The parameter `v` is of type `N | null`, which means it can either be of type `N` or `null`.
1384
+ */
1361
1385
  AbstractBinaryTree.prototype._setRoot = function (v) {
1362
1386
  if (v) {
1363
- v.parent = null;
1364
- v.familyPosition = types_1.FamilyPosition.ROOT;
1387
+ v.parent = undefined;
1365
1388
  }
1366
1389
  this._root = v;
1367
1390
  };
1391
+ /**
1392
+ * The function sets the size of a protected variable.
1393
+ * @param {number} v - number
1394
+ */
1368
1395
  AbstractBinaryTree.prototype._setSize = function (v) {
1369
1396
  this._size = v;
1370
1397
  };
1371
- AbstractBinaryTree.prototype._setCount = function (v) {
1372
- this._count = v;
1373
- };
1374
1398
  /**
1375
- * The function resets the values of several arrays used for tracking visited nodes and their properties.
1399
+ * The function `_resetResults` resets the values of several arrays used for tracking visited nodes and their
1400
+ * properties.
1376
1401
  */
1377
1402
  AbstractBinaryTree.prototype._resetResults = function () {
1378
1403
  this._visitedId = [];
1379
1404
  this._visitedVal = [];
1380
1405
  this._visitedNode = [];
1381
- this._visitedCount = [];
1382
1406
  this._visitedLeftSum = [];
1383
1407
  };
1384
1408
  /**
1385
1409
  * The function checks if a given property of a binary tree node matches a specified value, and if so, adds the node to
1386
1410
  * a result array.
1387
- * @param cur - The current binary tree node that is being checked.
1388
- * @param {(N | null | undefined)[]} result - An array that stores the matching nodes found during the
1389
- * traversal.
1390
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is the value that we are searching for in
1391
- * the binary tree nodes. It can be either the `id`, `count`, or `val` property of the node.
1411
+ * @param {N} cur - The current node being processed.
1412
+ * @param {(N | null | undefined)[]} result - An array that stores the matching nodes.
1413
+ * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter is either a `BinaryTreeNodeId` or a `N`
1414
+ * type. It represents the property value that we are comparing against in the switch statement.
1392
1415
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
1393
- * specifies the property of the `BinaryTreeNode` object that you want to compare with the `nodeProperty` value. It can
1394
- * be one of the following values: 'id', 'count', or 'val'. If no `propertyName` is provided,
1416
+ * specifies the property name to compare against when pushing nodes into the `result` array. It can be either `'id'`
1417
+ * or `'val'`. If it is not provided or is not equal to `'id'` or `'val'`, the
1395
1418
  * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
1396
1419
  * stop after finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set to
1397
1420
  * `true`, the function will stop after finding the first matching node and return `true`. If `onlyOne
1398
- * @returns a boolean value indicating whether or not a node was pushed into the result array.
1421
+ * @returns a boolean value indicating whether only one matching node should be pushed into the result array.
1399
1422
  */
1400
1423
  AbstractBinaryTree.prototype._pushByPropertyNameStopOrNot = function (cur, result, nodeProperty, propertyName, onlyOne) {
1401
1424
  switch (propertyName) {
@@ -1405,12 +1428,6 @@ var AbstractBinaryTree = /** @class */ (function () {
1405
1428
  return !!onlyOne;
1406
1429
  }
1407
1430
  break;
1408
- case 'count':
1409
- if (cur.count === nodeProperty) {
1410
- result.push(cur);
1411
- return !!onlyOne;
1412
- }
1413
- break;
1414
1431
  case 'val':
1415
1432
  if (cur.val === nodeProperty) {
1416
1433
  result.push(cur);
@@ -1426,12 +1443,11 @@ var AbstractBinaryTree = /** @class */ (function () {
1426
1443
  }
1427
1444
  };
1428
1445
  /**
1429
- * The function `_accumulatedByPropertyName` pushes a property value of a binary tree node into an array based on the
1430
- * provided property name or a default property name.
1431
- * @param node - The `node` parameter is of type `N`, which represents a node in a binary tree.
1432
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
1433
- * can be either a string representing a property name or a reference to a node object. If it is a string, it specifies
1434
- * the property name of the node that should be accumulated. If it is a node object, it specifies the node itself
1446
+ * The function `_accumulatedByPropertyName` accumulates values from a given node based on the specified property name.
1447
+ * @param {N} node - The `node` parameter is of type `N`, which represents a node in a data structure.
1448
+ * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
1449
+ * can be either a string representing a property name or a reference to a `Node` object. If it is a string, it
1450
+ * specifies the property name to be used for accumulating values. If it is a `Node` object, it specifies
1435
1451
  */
1436
1452
  AbstractBinaryTree.prototype._accumulatedByPropertyName = function (node, nodeOrPropertyName) {
1437
1453
  nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
@@ -1445,20 +1461,21 @@ var AbstractBinaryTree = /** @class */ (function () {
1445
1461
  case 'node':
1446
1462
  this._visitedNode.push(node);
1447
1463
  break;
1448
- case 'count':
1449
- this._visitedCount.push(node.count);
1450
- break;
1451
1464
  default:
1452
1465
  this._visitedId.push(node.id);
1453
1466
  break;
1454
1467
  }
1455
1468
  };
1456
1469
  /**
1457
- * The function `_getResultByPropertyName` returns different results based on the provided property name or defaulting
1458
- * to 'id'.
1470
+ * The time complexity of Morris traversal is O(n), it's may slower than others
1471
+ * The space complexity Morris traversal is O(1) because no using stack
1472
+ */
1473
+ /**
1474
+ * The function `_getResultByPropertyName` returns the corresponding property value based on the given node or property
1475
+ * name.
1459
1476
  * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
1460
- * can accept a value of type `NodeOrPropertyName`.
1461
- * @returns The method returns an object of type `AbstractBinaryTreeNodeProperties<T>`.
1477
+ * can accept either a `NodeOrPropertyName` type or be undefined.
1478
+ * @returns The method `_getResultByPropertyName` returns an instance of `AbstractBinaryTreeNodeProperties<N>`.
1462
1479
  */
1463
1480
  AbstractBinaryTree.prototype._getResultByPropertyName = function (nodeOrPropertyName) {
1464
1481
  nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
@@ -1469,8 +1486,6 @@ var AbstractBinaryTree = /** @class */ (function () {
1469
1486
  return this._visitedVal;
1470
1487
  case 'node':
1471
1488
  return this._visitedNode;
1472
- case 'count':
1473
- return this._visitedCount;
1474
1489
  default:
1475
1490
  return this._visitedId;
1476
1491
  }