data-structure-typed 1.18.6 → 1.18.8

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 (262) hide show
  1. package/README.md +154 -366
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +72 -51
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +226 -158
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +7 -6
  5. package/dist/data-structures/binary-tree/avl-tree.js +5 -3
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +16 -6
  7. package/dist/data-structures/binary-tree/binary-tree.js +16 -7
  8. package/dist/data-structures/binary-tree/bst.d.ts +37 -28
  9. package/dist/data-structures/binary-tree/bst.js +44 -76
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +30 -1
  11. package/dist/data-structures/binary-tree/rb-tree.js +27 -14
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +18 -7
  13. package/dist/data-structures/binary-tree/tree-multiset.js +20 -15
  14. package/dist/data-structures/graph/abstract-graph.d.ts +28 -27
  15. package/dist/data-structures/graph/abstract-graph.js +58 -36
  16. package/dist/data-structures/graph/directed-graph.d.ts +27 -24
  17. package/dist/data-structures/graph/directed-graph.js +65 -60
  18. package/dist/data-structures/graph/undirected-graph.d.ts +12 -18
  19. package/dist/data-structures/graph/undirected-graph.js +52 -65
  20. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +100 -0
  21. package/dist/data-structures/interfaces/abstract-binary-tree.js +2 -0
  22. package/dist/data-structures/interfaces/abstract-graph.d.ts +3 -8
  23. package/dist/data-structures/interfaces/avl-tree.d.ts +16 -1
  24. package/dist/data-structures/interfaces/binary-tree.d.ts +4 -24
  25. package/dist/data-structures/interfaces/bst.d.ts +18 -1
  26. package/dist/data-structures/interfaces/directed-graph.d.ts +4 -1
  27. package/dist/data-structures/interfaces/index.d.ts +1 -1
  28. package/dist/data-structures/interfaces/index.js +1 -1
  29. package/dist/data-structures/interfaces/rb-tree.d.ts +9 -0
  30. package/dist/data-structures/interfaces/rb-tree.js +2 -0
  31. package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
  32. package/dist/data-structures/interfaces/undirected-graph.d.ts +4 -1
  33. package/dist/data-structures/tree/tree.d.ts +1 -4
  34. package/dist/data-structures/tree/tree.js +1 -12
  35. package/dist/data-structures/types/abstract-binary-tree.d.ts +11 -7
  36. package/dist/data-structures/types/abstract-binary-tree.js +9 -5
  37. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  38. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  39. package/dist/data-structures/types/bst.d.ts +1 -1
  40. package/dist/data-structures/types/bst.js +1 -1
  41. package/dist/data-structures/types/directed-graph.js +1 -1
  42. package/dist/data-structures/types/helpers.d.ts +1 -8
  43. package/dist/data-structures/types/rb-tree.d.ts +2 -0
  44. package/dist/data-structures/types/rb-tree.js +1 -1
  45. package/dist/data-structures/types/tree-multiset.d.ts +4 -4
  46. package/dist/utils/types/utils.d.ts +18 -0
  47. package/dist/utils/utils.d.ts +6 -1
  48. package/dist/utils/utils.js +83 -1
  49. package/package.json +2 -2
  50. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  51. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  52. package/backup/recursive-type/src/assets/logo.png +0 -0
  53. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  54. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
  55. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
  56. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
  57. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
  58. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
  59. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
  60. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  61. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  62. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  63. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
  64. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
  65. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
  66. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
  67. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
  68. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  69. package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
  70. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
  71. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  72. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  73. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  74. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  75. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  76. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  77. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  78. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  79. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  80. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  81. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  82. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  83. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  84. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  85. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
  86. package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
  87. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
  88. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
  89. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
  90. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
  91. package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
  92. package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
  93. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
  94. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
  95. package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
  96. package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
  97. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
  98. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
  99. package/backup/recursive-type/src/data-structures/index.ts +0 -15
  100. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
  101. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
  102. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
  103. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
  104. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
  105. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
  106. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
  107. package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
  108. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
  109. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
  110. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
  111. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
  112. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
  113. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
  114. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  115. package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
  116. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
  117. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
  118. package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
  119. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
  120. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
  121. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
  122. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
  123. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
  124. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
  125. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
  126. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
  127. package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
  128. package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
  129. package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
  130. package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
  131. package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
  132. package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
  133. package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
  134. package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
  135. package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
  136. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
  137. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
  138. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
  139. package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
  140. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
  141. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
  142. package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
  143. package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
  144. package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
  145. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
  146. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
  147. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
  148. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
  149. package/backup/recursive-type/src/index.ts +0 -1
  150. package/backup/recursive-type/src/utils/index.ts +0 -2
  151. package/backup/recursive-type/src/utils/types/index.ts +0 -1
  152. package/backup/recursive-type/src/utils/types/utils.ts +0 -6
  153. package/backup/recursive-type/src/utils/utils.ts +0 -78
  154. package/docs/.nojekyll +0 -1
  155. package/docs/assets/highlight.css +0 -92
  156. package/docs/assets/main.js +0 -58
  157. package/docs/assets/search.js +0 -1
  158. package/docs/assets/style.css +0 -1367
  159. package/docs/classes/AVLTree.html +0 -2339
  160. package/docs/classes/AVLTreeNode.html +0 -450
  161. package/docs/classes/AaTree.html +0 -166
  162. package/docs/classes/AbstractBinaryTree.html +0 -2023
  163. package/docs/classes/AbstractBinaryTreeNode.html +0 -491
  164. package/docs/classes/AbstractEdge.html +0 -289
  165. package/docs/classes/AbstractGraph.html +0 -1046
  166. package/docs/classes/AbstractVertex.html +0 -252
  167. package/docs/classes/ArrayDeque.html +0 -433
  168. package/docs/classes/BST.html +0 -2196
  169. package/docs/classes/BSTNode.html +0 -453
  170. package/docs/classes/BTree.html +0 -166
  171. package/docs/classes/BinaryIndexedTree.html +0 -335
  172. package/docs/classes/BinaryTree.html +0 -2037
  173. package/docs/classes/BinaryTreeNode.html +0 -452
  174. package/docs/classes/Character.html +0 -214
  175. package/docs/classes/CoordinateMap.html +0 -477
  176. package/docs/classes/CoordinateSet.html +0 -438
  177. package/docs/classes/Deque.html +0 -969
  178. package/docs/classes/DirectedEdge.html +0 -360
  179. package/docs/classes/DirectedGraph.html +0 -1408
  180. package/docs/classes/DirectedVertex.html +0 -248
  181. package/docs/classes/DoublyLinkedList.html +0 -962
  182. package/docs/classes/DoublyLinkedListNode.html +0 -291
  183. package/docs/classes/HashTable.html +0 -166
  184. package/docs/classes/Heap.html +0 -417
  185. package/docs/classes/HeapItem.html +0 -249
  186. package/docs/classes/Matrix2D.html +0 -496
  187. package/docs/classes/MatrixNTI2D.html +0 -234
  188. package/docs/classes/MaxHeap.html +0 -430
  189. package/docs/classes/MaxPriorityQueue.html +0 -830
  190. package/docs/classes/MinHeap.html +0 -431
  191. package/docs/classes/MinPriorityQueue.html +0 -832
  192. package/docs/classes/Navigator.html +0 -307
  193. package/docs/classes/ObjectDeque.html +0 -449
  194. package/docs/classes/Pair.html +0 -166
  195. package/docs/classes/PriorityQueue.html +0 -754
  196. package/docs/classes/Queue.html +0 -386
  197. package/docs/classes/SegmentTree.html +0 -428
  198. package/docs/classes/SegmentTreeNode.html +0 -351
  199. package/docs/classes/SinglyLinkedList.html +0 -782
  200. package/docs/classes/SinglyLinkedListNode.html +0 -264
  201. package/docs/classes/SkipLinkedList.html +0 -166
  202. package/docs/classes/SplayTree.html +0 -166
  203. package/docs/classes/Stack.html +0 -362
  204. package/docs/classes/TreeMap.html +0 -166
  205. package/docs/classes/TreeMultiSet.html +0 -2196
  206. package/docs/classes/TreeMultiSetNode.html +0 -450
  207. package/docs/classes/TreeNode.html +0 -337
  208. package/docs/classes/TreeSet.html +0 -166
  209. package/docs/classes/Trie.html +0 -366
  210. package/docs/classes/TrieNode.html +0 -274
  211. package/docs/classes/TwoThreeTree.html +0 -166
  212. package/docs/classes/UndirectedEdge.html +0 -331
  213. package/docs/classes/UndirectedGraph.html +0 -1196
  214. package/docs/classes/UndirectedVertex.html +0 -248
  215. package/docs/classes/Vector2D.html +0 -799
  216. package/docs/enums/CP.html +0 -175
  217. package/docs/enums/FamilyPosition.html +0 -175
  218. package/docs/enums/LoopType.html +0 -176
  219. package/docs/enums/RBColor.html +0 -168
  220. package/docs/enums/TopologicalProperty.html +0 -175
  221. package/docs/index.html +0 -639
  222. package/docs/interfaces/IBinaryTree.html +0 -189
  223. package/docs/interfaces/IBinaryTreeNode.html +0 -396
  224. package/docs/interfaces/IDirectedGraph.html +0 -259
  225. package/docs/interfaces/IGraph.html +0 -471
  226. package/docs/interfaces/IUNDirectedGraph.html +0 -151
  227. package/docs/modules.html +0 -250
  228. package/docs/types/AVLTreeOptions.html +0 -144
  229. package/docs/types/AbstractBinaryTreeOptions.html +0 -150
  230. package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -146
  231. package/docs/types/AbstractResultByProperty.html +0 -146
  232. package/docs/types/AbstractResultsByProperty.html +0 -146
  233. package/docs/types/BSTComparator.html +0 -156
  234. package/docs/types/BSTOptions.html +0 -146
  235. package/docs/types/BinaryTreeDeletedResult.html +0 -153
  236. package/docs/types/BinaryTreeNodeId.html +0 -141
  237. package/docs/types/BinaryTreeNodePropertyName.html +0 -141
  238. package/docs/types/BinaryTreeOptions.html +0 -144
  239. package/docs/types/DFSOrderPattern.html +0 -141
  240. package/docs/types/DijkstraResult.html +0 -161
  241. package/docs/types/Direction.html +0 -141
  242. package/docs/types/EdgeId.html +0 -141
  243. package/docs/types/HeapOptions.html +0 -162
  244. package/docs/types/IdObject.html +0 -151
  245. package/docs/types/KeyValObject.html +0 -146
  246. package/docs/types/NavigatorParams.html +0 -175
  247. package/docs/types/NodeOrPropertyName.html +0 -141
  248. package/docs/types/PriorityQueueComparator.html +0 -161
  249. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -141
  250. package/docs/types/PriorityQueueOptions.html +0 -155
  251. package/docs/types/RBTreeOptions.html +0 -144
  252. package/docs/types/RecursiveAVLTreeNode.html +0 -146
  253. package/docs/types/RecursiveBSTNode.html +0 -146
  254. package/docs/types/RecursiveBinaryTreeNode.html +0 -146
  255. package/docs/types/RecursiveTreeMultiSetNode.html +0 -146
  256. package/docs/types/SegmentTreeNodeVal.html +0 -141
  257. package/docs/types/TopologicalStatus.html +0 -141
  258. package/docs/types/TreeMultiSetOptions.html +0 -146
  259. package/docs/types/Turning.html +0 -141
  260. package/docs/types/VertexId.html +0 -141
  261. package/notes/bst.test.ts +0 -181
  262. package/notes/note.md +0 -34
@@ -38,8 +38,16 @@ exports.AbstractBinaryTree = exports.AbstractBinaryTreeNode = void 0;
38
38
  var utils_1 = require("../../utils");
39
39
  var types_1 = require("../types");
40
40
  var AbstractBinaryTreeNode = /** @class */ (function () {
41
+ /**
42
+ * The constructor function initializes a BinaryTreeNode object with an id, value, and count.
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.
49
+ */
41
50
  function AbstractBinaryTreeNode(id, val, count) {
42
- this._familyPosition = types_1.FamilyPosition.ROOT;
43
51
  this._count = 1;
44
52
  this._height = 0;
45
53
  this._id = id;
@@ -60,8 +68,8 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
60
68
  get: function () {
61
69
  return this._val;
62
70
  },
63
- set: function (v) {
64
- this._val = v;
71
+ set: function (value) {
72
+ this._val = value;
65
73
  },
66
74
  enumerable: false,
67
75
  configurable: true
@@ -73,7 +81,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
73
81
  set: function (v) {
74
82
  if (v) {
75
83
  v.parent = this;
76
- v.familyPosition = types_1.FamilyPosition.LEFT;
77
84
  }
78
85
  this._left = v;
79
86
  },
@@ -87,7 +94,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
87
94
  set: function (v) {
88
95
  if (v) {
89
96
  v.parent = this;
90
- v.familyPosition = types_1.FamilyPosition.RIGHT;
91
97
  }
92
98
  this._right = v;
93
99
  },
@@ -104,16 +110,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
104
110
  enumerable: false,
105
111
  configurable: true
106
112
  });
107
- Object.defineProperty(AbstractBinaryTreeNode.prototype, "familyPosition", {
108
- get: function () {
109
- return this._familyPosition;
110
- },
111
- set: function (v) {
112
- this._familyPosition = v;
113
- },
114
- enumerable: false,
115
- configurable: true
116
- });
117
113
  Object.defineProperty(AbstractBinaryTreeNode.prototype, "count", {
118
114
  get: function () {
119
115
  return this._count;
@@ -134,26 +130,71 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
134
130
  enumerable: false,
135
131
  configurable: true
136
132
  });
137
- AbstractBinaryTreeNode.prototype.swapLocation = function (swapNode) {
138
- var val = swapNode.val, count = swapNode.count, height = swapNode.height;
139
- var tempNode = this._createNode(swapNode.id, val);
133
+ Object.defineProperty(AbstractBinaryTreeNode.prototype, "familyPosition", {
134
+ get: function () {
135
+ var that = this;
136
+ if (that.parent) {
137
+ if (that.parent.left === that) {
138
+ if (that.left || that.right) {
139
+ return types_1.FamilyPosition.ROOT_LEFT;
140
+ }
141
+ else {
142
+ return types_1.FamilyPosition.LEFT;
143
+ }
144
+ }
145
+ else if (that.parent.right === that) {
146
+ if (that.left || that.right) {
147
+ return types_1.FamilyPosition.ROOT_RIGHT;
148
+ }
149
+ else {
150
+ return types_1.FamilyPosition.RIGHT;
151
+ }
152
+ }
153
+ else {
154
+ return types_1.FamilyPosition.MAL_NODE;
155
+ }
156
+ }
157
+ else {
158
+ if (that.left || that.right) {
159
+ return types_1.FamilyPosition.ROOT;
160
+ }
161
+ else {
162
+ return types_1.FamilyPosition.ISOLATED;
163
+ }
164
+ }
165
+ },
166
+ enumerable: false,
167
+ configurable: true
168
+ });
169
+ /**
170
+ * The function swaps the location of two nodes in a binary tree.
171
+ * @param {FAMILY} destNode - The `swapNode` parameter is of type `FAMILY`, which represents a node in a family tree.
172
+ * @returns the `swapNode` object after swapping its properties with the properties of `this` object.
173
+ */
174
+ AbstractBinaryTreeNode.prototype.swapLocation = function (destNode) {
175
+ var val = destNode.val, count = destNode.count, height = destNode.height, id = destNode.id;
176
+ var tempNode = this.createNode(id, val, count);
177
+ tempNode.height = height;
140
178
  if (tempNode instanceof AbstractBinaryTreeNode) {
141
- tempNode.val = val;
142
- tempNode.count = count;
143
- tempNode.height = height;
144
- swapNode.id = this.id;
145
- swapNode.val = this.val;
146
- swapNode.count = this.count;
147
- swapNode.height = this.height;
179
+ // TODO should we consider the left, right children?
180
+ destNode.id = this.id;
181
+ destNode.val = this.val;
182
+ destNode.count = this.count;
183
+ destNode.height = this.height;
148
184
  this.id = tempNode.id;
149
185
  this.val = tempNode.val;
150
186
  this.count = tempNode.count;
151
187
  this.height = tempNode.height;
152
188
  }
153
- return swapNode;
189
+ return destNode;
154
190
  };
191
+ /**
192
+ * The `clone` function returns a new instance of the `FAMILY` class with the same `id`, `val`, and `count` properties.
193
+ * @returns The `clone()` method is returning a new instance of the `FAMILY` class with the same `id`, `val`, and
194
+ * `count` values as the current instance.
195
+ */
155
196
  AbstractBinaryTreeNode.prototype.clone = function () {
156
- return this._createNode(this.id, this.val, this.count);
197
+ return this.createNode(this.id, this.val, this.count);
157
198
  };
158
199
  return AbstractBinaryTreeNode;
159
200
  }());
@@ -173,13 +214,13 @@ var AbstractBinaryTree = /** @class */ (function () {
173
214
  this._visitedLeftSum = [];
174
215
  this._autoIncrementId = false;
175
216
  this._maxId = -1;
176
- this._isDuplicatedVal = false;
217
+ this._isMergeDuplicatedVal = true;
177
218
  this._root = null;
178
219
  this._size = 0;
179
220
  this._count = 0;
180
221
  if (options !== undefined) {
181
- 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;
182
- this._isDuplicatedVal = isDuplicatedVal;
222
+ 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;
223
+ this._isMergeDuplicatedVal = isMergeDuplicatedVal;
183
224
  this._autoIncrementId = autoIncrementId;
184
225
  this._loopType = loopType;
185
226
  }
@@ -240,9 +281,9 @@ var AbstractBinaryTree = /** @class */ (function () {
240
281
  enumerable: false,
241
282
  configurable: true
242
283
  });
243
- Object.defineProperty(AbstractBinaryTree.prototype, "isDuplicatedVal", {
284
+ Object.defineProperty(AbstractBinaryTree.prototype, "isMergeDuplicatedVal", {
244
285
  get: function () {
245
- return this._isDuplicatedVal;
286
+ return this._isMergeDuplicatedVal;
246
287
  },
247
288
  enumerable: false,
248
289
  configurable: true
@@ -317,7 +358,7 @@ var AbstractBinaryTree = /** @class */ (function () {
317
358
  return;
318
359
  };
319
360
  var inserted;
320
- var needInsert = val !== null ? this._createNode(id, val !== null && val !== void 0 ? val : id, count) : null;
361
+ var needInsert = val !== null ? this.createNode(id, val, count) : null;
321
362
  var existNode = val !== null ? this.get(id, 'id') : null;
322
363
  if (this.root) {
323
364
  if (existNode) {
@@ -333,7 +374,7 @@ var AbstractBinaryTree = /** @class */ (function () {
333
374
  }
334
375
  }
335
376
  else {
336
- this._setRoot(val !== null ? this._createNode(id, val !== null && val !== void 0 ? val : id, count) : null);
377
+ this._setRoot(val !== null ? this.createNode(id, val, count) : null);
337
378
  if (needInsert !== null) {
338
379
  this._setSize(1);
339
380
  this._setCount(count);
@@ -343,12 +384,13 @@ var AbstractBinaryTree = /** @class */ (function () {
343
384
  return inserted;
344
385
  };
345
386
  /**
346
- * The function inserts a new node into a binary tree as the left or right child of a given parent node.
347
- * @param {N | null} newNode - The `newNode` parameter is an instance of the `BinaryTreeNode` class or
348
- * `null`. It represents the node that needs to be inserted into the binary tree.
349
- * @param parent - The `parent` parameter is a BinaryTreeNode object representing the parent node to which the new node
350
- * will be inserted as a child.
351
- * @returns The method returns the newly inserted node, either as the left child or the right child of the parent node.
387
+ * The function adds a new node to a binary tree as the left or right child of a given parent node.
388
+ * @param {N | null} newNode - The `newNode` parameter represents the node that you want to add to the tree. It can be
389
+ * either a node object (`N`) or `null`.
390
+ * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
391
+ * child.
392
+ * @returns either the left or right child node that was added to the parent node. It can also return `null` or
393
+ * `undefined` in certain cases.
352
394
  */
353
395
  AbstractBinaryTree.prototype.addTo = function (newNode, parent) {
354
396
  var _a, _b;
@@ -356,7 +398,6 @@ var AbstractBinaryTree = /** @class */ (function () {
356
398
  if (parent.left === undefined) {
357
399
  if (newNode) {
358
400
  newNode.parent = parent;
359
- newNode.familyPosition = types_1.FamilyPosition.LEFT;
360
401
  }
361
402
  parent.left = newNode;
362
403
  if (newNode !== null) {
@@ -368,7 +409,6 @@ var AbstractBinaryTree = /** @class */ (function () {
368
409
  else if (parent.right === undefined) {
369
410
  if (newNode) {
370
411
  newNode.parent = parent;
371
- newNode.familyPosition = types_1.FamilyPosition.RIGHT;
372
412
  }
373
413
  parent.right = newNode;
374
414
  if (newNode !== null) {
@@ -395,13 +435,14 @@ var AbstractBinaryTree = /** @class */ (function () {
395
435
  AbstractBinaryTree.prototype.addMany = function (data) {
396
436
  var e_1, _a, e_2, _b;
397
437
  var _c;
438
+ // TODO not sure addMany not be run multi times
398
439
  var inserted = [];
399
440
  var map = new Map();
400
- if (!this._isDuplicatedVal) {
441
+ if (this.isMergeDuplicatedVal) {
401
442
  try {
402
443
  for (var data_1 = __values(data), data_1_1 = data_1.next(); !data_1_1.done; data_1_1 = data_1.next()) {
403
- var i = data_1_1.value;
404
- map.set(i, ((_c = map.get(i)) !== null && _c !== void 0 ? _c : 0) + 1);
444
+ var nodeOrId = data_1_1.value;
445
+ map.set(nodeOrId, ((_c = map.get(nodeOrId)) !== null && _c !== void 0 ? _c : 0) + 1);
405
446
  }
406
447
  }
407
448
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -414,53 +455,49 @@ var AbstractBinaryTree = /** @class */ (function () {
414
455
  }
415
456
  try {
416
457
  for (var data_2 = __values(data), data_2_1 = data_2.next(); !data_2_1.done; data_2_1 = data_2.next()) {
417
- var item = data_2_1.value;
458
+ var nodeOrId = data_2_1.value;
459
+ if (nodeOrId instanceof AbstractBinaryTreeNode) {
460
+ inserted.push(this.add(nodeOrId.id, nodeOrId.val, nodeOrId.count));
461
+ continue;
462
+ }
463
+ if (nodeOrId === null) {
464
+ inserted.push(this.add(NaN, null, 0));
465
+ continue;
466
+ }
418
467
  // TODO will this cause an issue?
419
- var count = this._isDuplicatedVal ? 1 : map.get(item);
420
- if (item instanceof AbstractBinaryTreeNode) {
421
- inserted.push(this.add(item.id, item.val, item.count));
468
+ var count = this.isMergeDuplicatedVal ? map.get(nodeOrId) : 1;
469
+ var newId = void 0;
470
+ if (typeof nodeOrId === 'number') {
471
+ newId = this.autoIncrementId ? this.maxId + 1 : nodeOrId;
422
472
  }
423
- else if (typeof item === 'number') {
424
- if (!this._autoIncrementId) {
425
- if (!this._isDuplicatedVal) {
426
- if (map.get(item) !== undefined) {
427
- inserted.push(this.add(item, item, count));
428
- map.delete(item);
429
- }
473
+ else if (nodeOrId instanceof Object) {
474
+ if (this.autoIncrementId) {
475
+ newId = this.maxId + 1;
476
+ }
477
+ else {
478
+ if (Object.keys(nodeOrId).includes('id')) {
479
+ newId = nodeOrId.id;
430
480
  }
431
481
  else {
432
- inserted.push(this.add(item, item, 1));
482
+ console.warn(nodeOrId, 'Object value must has an id property when the autoIncrementId is false');
483
+ continue;
433
484
  }
434
485
  }
435
486
  }
436
- else if (item instanceof Object) {
437
- if (!this._isDuplicatedVal) {
438
- if (map.has(item)) {
439
- var newId = void 0;
440
- if (!this._autoIncrementId) {
441
- if (Object.keys(item).includes('id')) {
442
- newId = item.id;
443
- }
444
- else {
445
- console.warn('Object value must has an id property when the autoIncrementId is false');
446
- break;
447
- }
448
- }
449
- else {
450
- newId = this.maxId + 1;
451
- this._setMaxId(newId);
452
- }
453
- inserted.push(this.add(newId, item, count));
454
- map.delete(item);
455
- }
456
- }
457
- else {
458
- inserted.push(this.add(++this._maxId, item, 1));
487
+ else {
488
+ console.warn(nodeOrId, " is not added");
489
+ continue;
490
+ }
491
+ if (this.isMergeDuplicatedVal) {
492
+ if (map.has(nodeOrId)) {
493
+ inserted.push(this.add(newId, nodeOrId, count));
494
+ map.delete(nodeOrId);
459
495
  }
460
496
  }
461
- else if (item === null) {
462
- inserted.push(this.add(Number.MAX_SAFE_INTEGER, item, 0));
497
+ else {
498
+ inserted.push(this.add(newId, nodeOrId, 1));
463
499
  }
500
+ this._setMaxId(newId);
464
501
  }
465
502
  }
466
503
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -484,62 +521,76 @@ var AbstractBinaryTree = /** @class */ (function () {
484
521
  return data.length === this.addMany(data).length;
485
522
  };
486
523
  /**
487
- * The function removes a node from a binary tree and returns information about the deleted node.
488
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to remove.
489
- * It is of type `BinaryTreeNodeId`.
524
+ * The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
525
+ * node that needs to be balanced.
526
+ * @param {N | BinaryTreeNodeId | null} nodeOrId - The `nodeOrId` parameter can be one of the following:
490
527
  * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
491
528
  * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
492
- * not be decremented and the overall count of the binary tree will not be updated. If `
493
- * @returns An array of objects is being returned. Each object in the array has two properties: "deleted" and
494
- * "needBalanced". The "deleted" property contains the deleted node or undefined if no node was deleted. The
495
- * "needBalanced" property is always null.
529
+ * not be taken into account when removing it. If `ignoreCount` is set to `false
530
+ * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
496
531
  */
497
- AbstractBinaryTree.prototype.remove = function (id, ignoreCount) {
498
- var nodes = this.getNodes(id, 'id', true);
499
- var node = nodes[0];
500
- if (!node)
501
- node = undefined;
502
- else if (node.count > 1 && !ignoreCount) {
503
- node.count--;
532
+ AbstractBinaryTree.prototype.remove = function (nodeOrId, ignoreCount) {
533
+ var bstDeletedResult = [];
534
+ if (!this.root)
535
+ return bstDeletedResult;
536
+ var curr = (typeof nodeOrId === 'number') ? this.get(nodeOrId) : nodeOrId;
537
+ if (!curr)
538
+ return bstDeletedResult;
539
+ var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
540
+ var needBalanced = null, orgCurrent = curr;
541
+ if (curr.count > 1 && !ignoreCount) {
542
+ curr.count--;
504
543
  this._setCount(this.count - 1);
505
544
  }
506
- else if (node instanceof AbstractBinaryTreeNode) {
507
- var _a = __read(this.getSubTreeSizeAndCount(node), 2), subSize = _a[0], subCount = _a[1];
508
- switch (node.familyPosition) {
509
- case 0:
510
- this._setSize(this.size - subSize);
511
- this._setCount(this.count - subCount);
512
- node = undefined;
513
- break;
514
- case 1:
515
- if (node.parent) {
516
- this._setSize(this.size - subSize);
517
- this._setCount(this.count - subCount);
518
- node.parent.left = null;
545
+ else {
546
+ if (!curr.left) {
547
+ if (!parent) {
548
+ if (curr.right !== undefined)
549
+ this._setRoot(curr.right);
550
+ }
551
+ else {
552
+ var fp = curr.familyPosition;
553
+ if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
554
+ parent.left = curr.right;
519
555
  }
520
- break;
521
- case 2:
522
- if (node.parent) {
523
- this._setSize(this.size - subSize);
524
- this._setCount(this.count - subCount);
525
- node.parent.right = null;
556
+ else if (fp === types_1.FamilyPosition.RIGHT || fp === types_1.FamilyPosition.ROOT_RIGHT) {
557
+ parent.right = curr.right;
526
558
  }
527
- break;
559
+ needBalanced = parent;
560
+ }
561
+ }
562
+ else {
563
+ var leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
564
+ if (leftSubTreeRightMost) {
565
+ var parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
566
+ orgCurrent = curr.swapLocation(leftSubTreeRightMost);
567
+ if (parentOfLeftSubTreeMax) {
568
+ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
569
+ parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
570
+ else
571
+ parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
572
+ needBalanced = parentOfLeftSubTreeMax;
573
+ }
574
+ }
528
575
  }
576
+ this._setSize(this.size - 1);
577
+ this._setCount(this.count - orgCurrent.count);
529
578
  }
530
- return [{ deleted: node, needBalanced: null }];
579
+ bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
580
+ return bstDeletedResult;
531
581
  };
532
582
  /**
533
- * The function calculates the depth of a binary tree node by traversing its parent nodes.
534
- * @param node - N - This is the node for which we want to calculate the depth. It is a generic type,
535
- * meaning it can represent any type of data that we want to store in the node.
536
- * @returns The depth of the given binary tree node.
583
+ * The function calculates the depth of a node in a binary tree.
584
+ * @param {N | BinaryTreeNodeId | null} beginRoot - The `beginRoot` parameter can be one of the following:
585
+ * @returns the depth of the given node or binary tree.
537
586
  */
538
- AbstractBinaryTree.prototype.getDepth = function (node) {
587
+ AbstractBinaryTree.prototype.getDepth = function (beginRoot) {
588
+ if (typeof beginRoot === 'number')
589
+ beginRoot = this.get(beginRoot, 'id');
539
590
  var depth = 0;
540
- while (node.parent) {
591
+ while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {
541
592
  depth++;
542
- node = node.parent;
593
+ beginRoot = beginRoot.parent;
543
594
  }
544
595
  return depth;
545
596
  };
@@ -554,6 +605,8 @@ var AbstractBinaryTree = /** @class */ (function () {
554
605
  AbstractBinaryTree.prototype.getHeight = function (beginRoot) {
555
606
  var _a, _b, _c;
556
607
  beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
608
+ if (typeof beginRoot === 'number')
609
+ beginRoot = this.get(beginRoot, 'id');
557
610
  if (!beginRoot)
558
611
  return -1;
559
612
  if (this._loopType === types_1.LoopType.RECURSIVE) {
@@ -742,24 +795,28 @@ var AbstractBinaryTree = /** @class */ (function () {
742
795
  return result;
743
796
  };
744
797
  /**
745
- * The `getLeftMost` function returns the leftmost node in a binary tree, either recursively or iteratively using tail
746
- * recursion optimization.
747
- * @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
748
- * | null`. It represents the starting node from which to find the leftmost node in a binary tree. If no node is
749
- * provided, the function will use the root node of the binary tree.
750
- * @returns The `getLeftMost` function returns the leftmost node in a binary tree.
798
+ * The `getLeftMost` function returns the leftmost node in a binary tree, starting from a specified node or the root if
799
+ * no node is specified.
800
+ * @param {N | BinaryTreeNodeId | null} [beginRoot] - The `beginRoot` parameter is optional and can be of type `N` (a
801
+ * generic type representing a node in a binary tree), `BinaryTreeNodeId` (a type representing the ID of a binary tree
802
+ * node), or `null`.
803
+ * @returns The function `getLeftMost` returns the leftmost node in a binary tree. If the `beginRoot` parameter is
804
+ * provided, it starts the traversal from that node. If `beginRoot` is not provided or is `null`, it starts the
805
+ * traversal from the root of the binary tree. If there are no nodes in the binary tree, it returns `null`.
751
806
  */
752
- AbstractBinaryTree.prototype.getLeftMost = function (node) {
753
- node = node !== null && node !== void 0 ? node : this.root;
754
- if (!node)
755
- return node;
807
+ AbstractBinaryTree.prototype.getLeftMost = function (beginRoot) {
808
+ if (typeof beginRoot === 'number')
809
+ beginRoot = this.get(beginRoot, 'id');
810
+ beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
811
+ if (!beginRoot)
812
+ return beginRoot;
756
813
  if (this._loopType === types_1.LoopType.RECURSIVE) {
757
814
  var _traverse_2 = function (cur) {
758
815
  if (!cur.left)
759
816
  return cur;
760
817
  return _traverse_2(cur.left);
761
818
  };
762
- return _traverse_2(node);
819
+ return _traverse_2(beginRoot);
763
820
  }
764
821
  else {
765
822
  // Indirect implementation of iteration using tail recursion optimization
@@ -768,7 +825,7 @@ var AbstractBinaryTree = /** @class */ (function () {
768
825
  return cur;
769
826
  return _traverse_3.cont(cur.left);
770
827
  });
771
- return _traverse_3(node);
828
+ return _traverse_3(beginRoot);
772
829
  }
773
830
  };
774
831
  /**
@@ -802,15 +859,12 @@ var AbstractBinaryTree = /** @class */ (function () {
802
859
  }
803
860
  };
804
861
  /**
805
- * The `isBST` function checks if a binary tree is a binary search tree.
806
- * @param {N | null} [node] - The `node` parameter is an optional parameter of type `N
807
- * | null`. It represents the root node of the binary search tree (BST) that we want to check for validity. If no node
808
- * is provided, the function will default to using the root node of the BST instance that
809
- * @returns The `isBST` function returns a boolean value. It returns `true` if the binary tree is a valid binary search
810
- * tree, and `false` otherwise.
862
+ * The function `isBSTByRooted` checks if a binary tree is a binary search tree (BST) by rooted traversal.
863
+ * @param {N | null} node - The `node` parameter represents the root node of a binary search tree (BST).
864
+ * @returns a boolean value.
811
865
  */
812
- AbstractBinaryTree.prototype.isBST = function (node) {
813
- node = node !== null && node !== void 0 ? node : this.root;
866
+ AbstractBinaryTree.prototype.isBSTByRooted = function (node) {
867
+ // TODO there is a bug
814
868
  if (!node)
815
869
  return true;
816
870
  if (this._loopType === types_1.LoopType.RECURSIVE) {
@@ -840,6 +894,15 @@ var AbstractBinaryTree = /** @class */ (function () {
840
894
  return true;
841
895
  }
842
896
  };
897
+ /**
898
+ * The function checks if a binary tree is a binary search tree.
899
+ * @param {N | null} [node] - The `node` parameter is of type `N` or `null`. It represents the root node of a binary
900
+ * search tree (BST).
901
+ * @returns a boolean value.
902
+ */
903
+ AbstractBinaryTree.prototype.isBST = function (node) {
904
+ return this.isBSTByRooted(this.root);
905
+ };
843
906
  /**
844
907
  * The function calculates the size and count of a subtree in a binary tree using either recursive or iterative
845
908
  * traversal.
@@ -887,6 +950,8 @@ var AbstractBinaryTree = /** @class */ (function () {
887
950
  */
888
951
  AbstractBinaryTree.prototype.subTreeSum = function (subTreeRoot, propertyName) {
889
952
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
953
+ if (typeof subTreeRoot === 'number')
954
+ subTreeRoot = this.get(subTreeRoot, 'id');
890
955
  if (!subTreeRoot)
891
956
  return 0;
892
957
  var sum = 0;
@@ -928,17 +993,21 @@ var AbstractBinaryTree = /** @class */ (function () {
928
993
  return sum;
929
994
  };
930
995
  /**
931
- * The function `subTreeAdd` adds a specified delta value to a property of each node in a binary tree.
932
- * @param subTreeRoot - The `subTreeRoot` parameter is the root node of the subtree where the values will be modified.
996
+ * The function `subTreeAdd` adds a delta value to a specified property of each node in a subtree.
997
+ * @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a binary
998
+ * tree or the ID of a binary tree node. It can also be `null` if there is no subtree root.
933
999
  * @param {number} delta - The `delta` parameter is a number that represents the amount by which the property value of
934
- * each node in the subtree should be increased or decreased.
1000
+ * each node in the subtree should be incremented or decremented.
935
1001
  * @param {BinaryTreeNodePropertyName} [propertyName] - The `propertyName` parameter is an optional parameter that
936
- * specifies the property of the `BinaryTreeNode` that should be modified. It defaults to `'id'` if not provided.
937
- * @returns a boolean value, which is `true`.
1002
+ * specifies the property of the binary tree node that should be modified. It can be either 'id' or 'count'. If no
1003
+ * value is provided for `propertyName`, it defaults to 'id'.
1004
+ * @returns a boolean value.
938
1005
  */
939
1006
  AbstractBinaryTree.prototype.subTreeAdd = function (subTreeRoot, delta, propertyName) {
940
1007
  var _this = this;
941
1008
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
1009
+ if (typeof subTreeRoot === 'number')
1010
+ subTreeRoot = this.get(subTreeRoot, 'id');
942
1011
  if (!subTreeRoot)
943
1012
  return false;
944
1013
  var _addByProperty = function (cur) {
@@ -981,7 +1050,7 @@ var AbstractBinaryTree = /** @class */ (function () {
981
1050
  * represents either a node or a property name. If a node is provided, the breadth-first search algorithm will be
982
1051
  * performed starting from that node. If a property name is provided, the breadth-first search algorithm will be
983
1052
  * performed starting from the root node
984
- * @returns an object of type `AbstractResultsByProperty<N>`.
1053
+ * @returns an object of type `AbstractBinaryTreeNodeProperties<N>`.
985
1054
  */
986
1055
  AbstractBinaryTree.prototype.BFS = function (nodeOrPropertyName) {
987
1056
  nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';
@@ -1009,7 +1078,7 @@ var AbstractBinaryTree = /** @class */ (function () {
1009
1078
  * either the name of a property in the `BinaryTreeNode` object or the value of the `id` property in the
1010
1079
  * `BinaryTreeNode` object. This parameter is used to accumulate the results based on the specified property name. If
1011
1080
  * no value
1012
- * @returns an object of type `AbstractResultsByProperty<N>`.
1081
+ * @returns an object of type `AbstractBinaryTreeNodeProperties<N>`.
1013
1082
  */
1014
1083
  AbstractBinaryTree.prototype.DFS = function (pattern, nodeOrPropertyName) {
1015
1084
  var _this = this;
@@ -1103,7 +1172,7 @@ var AbstractBinaryTree = /** @class */ (function () {
1103
1172
  * can be either a `BinaryTreeNode` property name or the string `'id'`. If a property name is provided, the function
1104
1173
  * will accumulate results based on that property. If no property name is provided, the function will default to
1105
1174
  * accumulating results
1106
- * @returns The function `levelIterative` returns an object of type `AbstractResultsByProperty<N>`.
1175
+ * @returns The function `levelIterative` returns an object of type `AbstractBinaryTreeNodeProperties<N>`.
1107
1176
  */
1108
1177
  AbstractBinaryTree.prototype.levelIterative = function (node, nodeOrPropertyName) {
1109
1178
  nodeOrPropertyName = nodeOrPropertyName || 'id';
@@ -1133,7 +1202,7 @@ var AbstractBinaryTree = /** @class */ (function () {
1133
1202
  * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
1134
1203
  * specifies the property of the `BinaryTreeNode` object to collect at each level. It can be one of the following
1135
1204
  * values:
1136
- * @returns The function `listLevels` returns a 2D array of `AbstractResultByProperty<N>` objects.
1205
+ * @returns The function `listLevels` returns a 2D array of `AbstractBinaryTreeNodeProperty<N>` objects.
1137
1206
  */
1138
1207
  AbstractBinaryTree.prototype.listLevels = function (node, nodeOrPropertyName) {
1139
1208
  nodeOrPropertyName = nodeOrPropertyName || 'id';
@@ -1217,7 +1286,7 @@ var AbstractBinaryTree = /** @class */ (function () {
1217
1286
  * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is used to specify the
1218
1287
  * property of the nodes that you want to retrieve in the results. It can be either the node itself or the name of the
1219
1288
  * property. If not provided, it defaults to `'id'`.
1220
- * @returns The function `morris` returns an object of type `AbstractResultsByProperty<N>`.
1289
+ * @returns The function `morris` returns an object of type `AbstractBinaryTreeNodeProperties<N>`.
1221
1290
  */
1222
1291
  AbstractBinaryTree.prototype.morris = function (pattern, nodeOrPropertyName) {
1223
1292
  var _this = this;
@@ -1331,12 +1400,11 @@ var AbstractBinaryTree = /** @class */ (function () {
1331
1400
  this._maxId = value;
1332
1401
  };
1333
1402
  AbstractBinaryTree.prototype._setIsDuplicatedVal = function (value) {
1334
- this._isDuplicatedVal = value;
1403
+ this._isMergeDuplicatedVal = value;
1335
1404
  };
1336
1405
  AbstractBinaryTree.prototype._setRoot = function (v) {
1337
1406
  if (v) {
1338
- v.parent = null;
1339
- v.familyPosition = types_1.FamilyPosition.ROOT;
1407
+ v.parent = undefined;
1340
1408
  }
1341
1409
  this._root = v;
1342
1410
  };
@@ -1433,7 +1501,7 @@ var AbstractBinaryTree = /** @class */ (function () {
1433
1501
  * to 'id'.
1434
1502
  * @param {NodeOrPropertyName} [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is an optional parameter that
1435
1503
  * can accept a value of type `NodeOrPropertyName`.
1436
- * @returns The method returns an object of type `AbstractResultsByProperty<T>`.
1504
+ * @returns The method returns an object of type `AbstractBinaryTreeNodeProperties<T>`.
1437
1505
  */
1438
1506
  AbstractBinaryTree.prototype._getResultByPropertyName = function (nodeOrPropertyName) {
1439
1507
  nodeOrPropertyName = nodeOrPropertyName !== null && nodeOrPropertyName !== void 0 ? nodeOrPropertyName : 'id';