data-structure-typed 1.18.7 → 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 (260) hide show
  1. package/README.md +154 -366
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +29 -32
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +179 -136
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +4 -4
  5. package/dist/data-structures/binary-tree/avl-tree.js +2 -2
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +3 -3
  7. package/dist/data-structures/binary-tree/binary-tree.js +4 -4
  8. package/dist/data-structures/binary-tree/bst.d.ts +13 -25
  9. package/dist/data-structures/binary-tree/bst.js +20 -74
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -6
  11. package/dist/data-structures/binary-tree/tree-multiset.d.ts +6 -6
  12. package/dist/data-structures/binary-tree/tree-multiset.js +7 -14
  13. package/dist/data-structures/graph/abstract-graph.d.ts +11 -9
  14. package/dist/data-structures/graph/abstract-graph.js +39 -22
  15. package/dist/data-structures/graph/directed-graph.d.ts +17 -15
  16. package/dist/data-structures/graph/directed-graph.js +47 -42
  17. package/dist/data-structures/graph/undirected-graph.d.ts +7 -7
  18. package/dist/data-structures/graph/undirected-graph.js +48 -48
  19. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +2 -3
  20. package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
  21. package/dist/data-structures/interfaces/avl-tree.d.ts +1 -1
  22. package/dist/data-structures/interfaces/bst.d.ts +2 -2
  23. package/dist/data-structures/interfaces/rb-tree.d.ts +2 -2
  24. package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
  25. package/dist/data-structures/tree/tree.d.ts +1 -4
  26. package/dist/data-structures/tree/tree.js +1 -12
  27. package/dist/data-structures/types/abstract-binary-tree.d.ts +9 -5
  28. package/dist/data-structures/types/abstract-binary-tree.js +9 -5
  29. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  30. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  31. package/dist/data-structures/types/bst.d.ts +1 -1
  32. package/dist/data-structures/types/bst.js +1 -1
  33. package/dist/data-structures/types/directed-graph.js +1 -1
  34. package/dist/data-structures/types/helpers.d.ts +1 -8
  35. package/dist/data-structures/types/rb-tree.d.ts +2 -0
  36. package/dist/data-structures/types/rb-tree.js +1 -1
  37. package/dist/data-structures/types/tree-multiset.d.ts +4 -4
  38. package/dist/utils/types/utils.d.ts +18 -0
  39. package/dist/utils/utils.d.ts +6 -1
  40. package/dist/utils/utils.js +21 -1
  41. package/package.json +2 -2
  42. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  43. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  44. package/backup/recursive-type/src/assets/logo.png +0 -0
  45. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  46. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
  47. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
  48. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
  49. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
  50. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
  51. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
  52. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  53. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  54. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  55. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
  56. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
  57. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
  58. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
  59. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
  60. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  61. package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
  62. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
  63. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  64. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  65. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  66. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  67. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  68. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  69. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  70. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  71. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  72. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  73. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  74. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  75. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  76. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  77. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
  78. package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
  79. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
  80. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
  81. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
  82. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
  83. package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
  84. package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
  85. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
  86. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
  87. package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
  88. package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
  89. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
  90. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
  91. package/backup/recursive-type/src/data-structures/index.ts +0 -15
  92. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
  93. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
  94. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
  95. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
  96. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
  97. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
  98. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
  99. package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
  100. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
  101. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
  102. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
  103. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
  104. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
  105. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
  106. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  107. package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
  108. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
  109. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
  110. package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
  111. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
  112. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
  113. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
  114. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
  115. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
  116. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
  117. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
  118. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
  119. package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
  120. package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
  121. package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
  122. package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
  123. package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
  124. package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
  125. package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
  126. package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
  127. package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
  128. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
  129. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
  130. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
  131. package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
  132. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
  133. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
  134. package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
  135. package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
  136. package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
  137. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
  138. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
  139. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
  140. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
  141. package/backup/recursive-type/src/index.ts +0 -1
  142. package/backup/recursive-type/src/utils/index.ts +0 -2
  143. package/backup/recursive-type/src/utils/types/index.ts +0 -1
  144. package/backup/recursive-type/src/utils/types/utils.ts +0 -6
  145. package/backup/recursive-type/src/utils/utils.ts +0 -78
  146. package/docs/.nojekyll +0 -1
  147. package/docs/assets/highlight.css +0 -92
  148. package/docs/assets/main.js +0 -58
  149. package/docs/assets/search.js +0 -1
  150. package/docs/assets/style.css +0 -1367
  151. package/docs/classes/AVLTree.html +0 -2451
  152. package/docs/classes/AVLTreeNode.html +0 -499
  153. package/docs/classes/AaTree.html +0 -172
  154. package/docs/classes/AbstractBinaryTree.html +0 -2118
  155. package/docs/classes/AbstractBinaryTreeNode.html +0 -524
  156. package/docs/classes/AbstractEdge.html +0 -295
  157. package/docs/classes/AbstractGraph.html +0 -1043
  158. package/docs/classes/AbstractVertex.html +0 -258
  159. package/docs/classes/ArrayDeque.html +0 -439
  160. package/docs/classes/BST.html +0 -2297
  161. package/docs/classes/BSTNode.html +0 -503
  162. package/docs/classes/BTree.html +0 -172
  163. package/docs/classes/BinaryIndexedTree.html +0 -341
  164. package/docs/classes/BinaryTree.html +0 -2133
  165. package/docs/classes/BinaryTreeNode.html +0 -501
  166. package/docs/classes/Character.html +0 -220
  167. package/docs/classes/CoordinateMap.html +0 -483
  168. package/docs/classes/CoordinateSet.html +0 -444
  169. package/docs/classes/Deque.html +0 -975
  170. package/docs/classes/DirectedEdge.html +0 -366
  171. package/docs/classes/DirectedGraph.html +0 -1443
  172. package/docs/classes/DirectedVertex.html +0 -254
  173. package/docs/classes/DoublyLinkedList.html +0 -968
  174. package/docs/classes/DoublyLinkedListNode.html +0 -297
  175. package/docs/classes/HashTable.html +0 -172
  176. package/docs/classes/Heap.html +0 -423
  177. package/docs/classes/HeapItem.html +0 -255
  178. package/docs/classes/Matrix2D.html +0 -502
  179. package/docs/classes/MatrixNTI2D.html +0 -240
  180. package/docs/classes/MaxHeap.html +0 -436
  181. package/docs/classes/MaxPriorityQueue.html +0 -836
  182. package/docs/classes/MinHeap.html +0 -437
  183. package/docs/classes/MinPriorityQueue.html +0 -838
  184. package/docs/classes/Navigator.html +0 -313
  185. package/docs/classes/ObjectDeque.html +0 -455
  186. package/docs/classes/Pair.html +0 -172
  187. package/docs/classes/PriorityQueue.html +0 -760
  188. package/docs/classes/Queue.html +0 -392
  189. package/docs/classes/RBTree.html +0 -2388
  190. package/docs/classes/RBTreeNode.html +0 -516
  191. package/docs/classes/SegmentTree.html +0 -434
  192. package/docs/classes/SegmentTreeNode.html +0 -357
  193. package/docs/classes/SinglyLinkedList.html +0 -788
  194. package/docs/classes/SinglyLinkedListNode.html +0 -270
  195. package/docs/classes/SkipLinkedList.html +0 -172
  196. package/docs/classes/SplayTree.html +0 -172
  197. package/docs/classes/Stack.html +0 -368
  198. package/docs/classes/TreeMap.html +0 -172
  199. package/docs/classes/TreeMultiSet.html +0 -2297
  200. package/docs/classes/TreeMultiSetNode.html +0 -499
  201. package/docs/classes/TreeNode.html +0 -343
  202. package/docs/classes/TreeSet.html +0 -172
  203. package/docs/classes/Trie.html +0 -372
  204. package/docs/classes/TrieNode.html +0 -280
  205. package/docs/classes/TwoThreeTree.html +0 -172
  206. package/docs/classes/UndirectedEdge.html +0 -337
  207. package/docs/classes/UndirectedGraph.html +0 -1210
  208. package/docs/classes/UndirectedVertex.html +0 -254
  209. package/docs/classes/Vector2D.html +0 -805
  210. package/docs/enums/CP.html +0 -181
  211. package/docs/enums/FamilyPosition.html +0 -181
  212. package/docs/enums/LoopType.html +0 -182
  213. package/docs/enums/RBColor.html +0 -174
  214. package/docs/enums/TopologicalProperty.html +0 -181
  215. package/docs/index.html +0 -645
  216. package/docs/interfaces/IAVLTree.html +0 -1378
  217. package/docs/interfaces/IAVLTreeNode.html +0 -405
  218. package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
  219. package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
  220. package/docs/interfaces/IAbstractGraph.html +0 -433
  221. package/docs/interfaces/IBST.html +0 -1271
  222. package/docs/interfaces/IBSTNode.html +0 -408
  223. package/docs/interfaces/IDirectedGraph.html +0 -572
  224. package/docs/interfaces/IUNDirectedGraph.html +0 -465
  225. package/docs/modules.html +0 -262
  226. package/docs/types/AVLTreeOptions.html +0 -150
  227. package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
  228. package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
  229. package/docs/types/AbstractBinaryTreeOptions.html +0 -156
  230. package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
  231. package/docs/types/BSTComparator.html +0 -162
  232. package/docs/types/BSTOptions.html +0 -152
  233. package/docs/types/BinaryTreeDeletedResult.html +0 -159
  234. package/docs/types/BinaryTreeNodeId.html +0 -147
  235. package/docs/types/BinaryTreeNodePropertyName.html +0 -147
  236. package/docs/types/BinaryTreeOptions.html +0 -150
  237. package/docs/types/DFSOrderPattern.html +0 -147
  238. package/docs/types/DijkstraResult.html +0 -167
  239. package/docs/types/Direction.html +0 -147
  240. package/docs/types/EdgeId.html +0 -147
  241. package/docs/types/HeapOptions.html +0 -168
  242. package/docs/types/IdObject.html +0 -157
  243. package/docs/types/KeyValObject.html +0 -152
  244. package/docs/types/NavigatorParams.html +0 -181
  245. package/docs/types/NodeOrPropertyName.html +0 -147
  246. package/docs/types/PriorityQueueComparator.html +0 -167
  247. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
  248. package/docs/types/PriorityQueueOptions.html +0 -161
  249. package/docs/types/RBTreeOptions.html +0 -150
  250. package/docs/types/RecursiveAVLTreeNode.html +0 -152
  251. package/docs/types/RecursiveBSTNode.html +0 -152
  252. package/docs/types/RecursiveBinaryTreeNode.html +0 -152
  253. package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
  254. package/docs/types/SegmentTreeNodeVal.html +0 -147
  255. package/docs/types/TopologicalStatus.html +0 -147
  256. package/docs/types/TreeMultiSetOptions.html +0 -152
  257. package/docs/types/Turning.html +0 -147
  258. package/docs/types/VertexId.html +0 -147
  259. package/notes/bst.test.ts +0 -181
  260. package/notes/note.md +0 -34
@@ -48,7 +48,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
48
48
  * value `val` appears in the binary tree node. If the `count` parameter is not provided, it defaults to 1.
49
49
  */
50
50
  function AbstractBinaryTreeNode(id, val, count) {
51
- this._familyPosition = types_1.FamilyPosition.ROOT;
52
51
  this._count = 1;
53
52
  this._height = 0;
54
53
  this._id = id;
@@ -82,7 +81,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
82
81
  set: function (v) {
83
82
  if (v) {
84
83
  v.parent = this;
85
- v.familyPosition = types_1.FamilyPosition.LEFT;
86
84
  }
87
85
  this._left = v;
88
86
  },
@@ -96,7 +94,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
96
94
  set: function (v) {
97
95
  if (v) {
98
96
  v.parent = this;
99
- v.familyPosition = types_1.FamilyPosition.RIGHT;
100
97
  }
101
98
  this._right = v;
102
99
  },
@@ -113,16 +110,6 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
113
110
  enumerable: false,
114
111
  configurable: true
115
112
  });
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
113
  Object.defineProperty(AbstractBinaryTreeNode.prototype, "count", {
127
114
  get: function () {
128
115
  return this._count;
@@ -143,28 +130,63 @@ var AbstractBinaryTreeNode = /** @class */ (function () {
143
130
  enumerable: false,
144
131
  configurable: true
145
132
  });
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
+ });
146
169
  /**
147
170
  * 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.
171
+ * @param {FAMILY} destNode - The `swapNode` parameter is of type `FAMILY`, which represents a node in a family tree.
149
172
  * @returns the `swapNode` object after swapping its properties with the properties of `this` object.
150
173
  */
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);
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;
154
178
  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;
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;
162
184
  this.id = tempNode.id;
163
185
  this.val = tempNode.val;
164
186
  this.count = tempNode.count;
165
187
  this.height = tempNode.height;
166
188
  }
167
- return swapNode;
189
+ return destNode;
168
190
  };
169
191
  /**
170
192
  * The `clone` function returns a new instance of the `FAMILY` class with the same `id`, `val`, and `count` properties.
@@ -192,13 +214,13 @@ var AbstractBinaryTree = /** @class */ (function () {
192
214
  this._visitedLeftSum = [];
193
215
  this._autoIncrementId = false;
194
216
  this._maxId = -1;
195
- this._isDuplicatedVal = false;
217
+ this._isMergeDuplicatedVal = true;
196
218
  this._root = null;
197
219
  this._size = 0;
198
220
  this._count = 0;
199
221
  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;
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;
202
224
  this._autoIncrementId = autoIncrementId;
203
225
  this._loopType = loopType;
204
226
  }
@@ -259,9 +281,9 @@ var AbstractBinaryTree = /** @class */ (function () {
259
281
  enumerable: false,
260
282
  configurable: true
261
283
  });
262
- Object.defineProperty(AbstractBinaryTree.prototype, "isDuplicatedVal", {
284
+ Object.defineProperty(AbstractBinaryTree.prototype, "isMergeDuplicatedVal", {
263
285
  get: function () {
264
- return this._isDuplicatedVal;
286
+ return this._isMergeDuplicatedVal;
265
287
  },
266
288
  enumerable: false,
267
289
  configurable: true
@@ -336,7 +358,7 @@ var AbstractBinaryTree = /** @class */ (function () {
336
358
  return;
337
359
  };
338
360
  var inserted;
339
- 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;
340
362
  var existNode = val !== null ? this.get(id, 'id') : null;
341
363
  if (this.root) {
342
364
  if (existNode) {
@@ -352,7 +374,7 @@ var AbstractBinaryTree = /** @class */ (function () {
352
374
  }
353
375
  }
354
376
  else {
355
- 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);
356
378
  if (needInsert !== null) {
357
379
  this._setSize(1);
358
380
  this._setCount(count);
@@ -376,7 +398,6 @@ var AbstractBinaryTree = /** @class */ (function () {
376
398
  if (parent.left === undefined) {
377
399
  if (newNode) {
378
400
  newNode.parent = parent;
379
- newNode.familyPosition = types_1.FamilyPosition.LEFT;
380
401
  }
381
402
  parent.left = newNode;
382
403
  if (newNode !== null) {
@@ -388,7 +409,6 @@ var AbstractBinaryTree = /** @class */ (function () {
388
409
  else if (parent.right === undefined) {
389
410
  if (newNode) {
390
411
  newNode.parent = parent;
391
- newNode.familyPosition = types_1.FamilyPosition.RIGHT;
392
412
  }
393
413
  parent.right = newNode;
394
414
  if (newNode !== null) {
@@ -415,13 +435,14 @@ var AbstractBinaryTree = /** @class */ (function () {
415
435
  AbstractBinaryTree.prototype.addMany = function (data) {
416
436
  var e_1, _a, e_2, _b;
417
437
  var _c;
438
+ // TODO not sure addMany not be run multi times
418
439
  var inserted = [];
419
440
  var map = new Map();
420
- if (!this._isDuplicatedVal) {
441
+ if (this.isMergeDuplicatedVal) {
421
442
  try {
422
443
  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);
444
+ var nodeOrId = data_1_1.value;
445
+ map.set(nodeOrId, ((_c = map.get(nodeOrId)) !== null && _c !== void 0 ? _c : 0) + 1);
425
446
  }
426
447
  }
427
448
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -434,53 +455,49 @@ var AbstractBinaryTree = /** @class */ (function () {
434
455
  }
435
456
  try {
436
457
  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;
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
+ }
438
467
  // 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));
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;
442
472
  }
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
- }
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;
450
480
  }
451
481
  else {
452
- 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;
453
484
  }
454
485
  }
455
486
  }
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));
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);
479
495
  }
480
496
  }
481
- else if (item === null) {
482
- inserted.push(this.add(Number.MAX_SAFE_INTEGER, item, 0));
497
+ else {
498
+ inserted.push(this.add(newId, nodeOrId, 1));
483
499
  }
500
+ this._setMaxId(newId);
484
501
  }
485
502
  }
486
503
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -504,62 +521,76 @@ var AbstractBinaryTree = /** @class */ (function () {
504
521
  return data.length === this.addMany(data).length;
505
522
  };
506
523
  /**
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`.
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:
510
527
  * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
511
528
  * 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.
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.
516
531
  */
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--;
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--;
524
543
  this._setCount(this.count - 1);
525
544
  }
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;
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;
539
555
  }
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;
556
+ else if (fp === types_1.FamilyPosition.RIGHT || fp === types_1.FamilyPosition.ROOT_RIGHT) {
557
+ parent.right = curr.right;
546
558
  }
547
- 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
+ }
548
575
  }
576
+ this._setSize(this.size - 1);
577
+ this._setCount(this.count - orgCurrent.count);
549
578
  }
550
- return [{ deleted: node, needBalanced: null }];
579
+ bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
580
+ return bstDeletedResult;
551
581
  };
552
582
  /**
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.
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.
557
586
  */
558
- AbstractBinaryTree.prototype.getDepth = function (node) {
587
+ AbstractBinaryTree.prototype.getDepth = function (beginRoot) {
588
+ if (typeof beginRoot === 'number')
589
+ beginRoot = this.get(beginRoot, 'id');
559
590
  var depth = 0;
560
- while (node.parent) {
591
+ while (beginRoot === null || beginRoot === void 0 ? void 0 : beginRoot.parent) {
561
592
  depth++;
562
- node = node.parent;
593
+ beginRoot = beginRoot.parent;
563
594
  }
564
595
  return depth;
565
596
  };
@@ -574,6 +605,8 @@ var AbstractBinaryTree = /** @class */ (function () {
574
605
  AbstractBinaryTree.prototype.getHeight = function (beginRoot) {
575
606
  var _a, _b, _c;
576
607
  beginRoot = beginRoot !== null && beginRoot !== void 0 ? beginRoot : this.root;
608
+ if (typeof beginRoot === 'number')
609
+ beginRoot = this.get(beginRoot, 'id');
577
610
  if (!beginRoot)
578
611
  return -1;
579
612
  if (this._loopType === types_1.LoopType.RECURSIVE) {
@@ -762,24 +795,28 @@ var AbstractBinaryTree = /** @class */ (function () {
762
795
  return result;
763
796
  };
764
797
  /**
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.
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`.
771
806
  */
772
- AbstractBinaryTree.prototype.getLeftMost = function (node) {
773
- node = node !== null && node !== void 0 ? node : this.root;
774
- if (!node)
775
- 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;
776
813
  if (this._loopType === types_1.LoopType.RECURSIVE) {
777
814
  var _traverse_2 = function (cur) {
778
815
  if (!cur.left)
779
816
  return cur;
780
817
  return _traverse_2(cur.left);
781
818
  };
782
- return _traverse_2(node);
819
+ return _traverse_2(beginRoot);
783
820
  }
784
821
  else {
785
822
  // Indirect implementation of iteration using tail recursion optimization
@@ -788,7 +825,7 @@ var AbstractBinaryTree = /** @class */ (function () {
788
825
  return cur;
789
826
  return _traverse_3.cont(cur.left);
790
827
  });
791
- return _traverse_3(node);
828
+ return _traverse_3(beginRoot);
792
829
  }
793
830
  };
794
831
  /**
@@ -827,6 +864,7 @@ var AbstractBinaryTree = /** @class */ (function () {
827
864
  * @returns a boolean value.
828
865
  */
829
866
  AbstractBinaryTree.prototype.isBSTByRooted = function (node) {
867
+ // TODO there is a bug
830
868
  if (!node)
831
869
  return true;
832
870
  if (this._loopType === types_1.LoopType.RECURSIVE) {
@@ -912,6 +950,8 @@ var AbstractBinaryTree = /** @class */ (function () {
912
950
  */
913
951
  AbstractBinaryTree.prototype.subTreeSum = function (subTreeRoot, propertyName) {
914
952
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
953
+ if (typeof subTreeRoot === 'number')
954
+ subTreeRoot = this.get(subTreeRoot, 'id');
915
955
  if (!subTreeRoot)
916
956
  return 0;
917
957
  var sum = 0;
@@ -953,17 +993,21 @@ var AbstractBinaryTree = /** @class */ (function () {
953
993
  return sum;
954
994
  };
955
995
  /**
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.
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.
958
999
  * @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.
1000
+ * each node in the subtree should be incremented or decremented.
960
1001
  * @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`.
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.
963
1005
  */
964
1006
  AbstractBinaryTree.prototype.subTreeAdd = function (subTreeRoot, delta, propertyName) {
965
1007
  var _this = this;
966
1008
  propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
1009
+ if (typeof subTreeRoot === 'number')
1010
+ subTreeRoot = this.get(subTreeRoot, 'id');
967
1011
  if (!subTreeRoot)
968
1012
  return false;
969
1013
  var _addByProperty = function (cur) {
@@ -1356,12 +1400,11 @@ var AbstractBinaryTree = /** @class */ (function () {
1356
1400
  this._maxId = value;
1357
1401
  };
1358
1402
  AbstractBinaryTree.prototype._setIsDuplicatedVal = function (value) {
1359
- this._isDuplicatedVal = value;
1403
+ this._isMergeDuplicatedVal = value;
1360
1404
  };
1361
1405
  AbstractBinaryTree.prototype._setRoot = function (v) {
1362
1406
  if (v) {
1363
- v.parent = null;
1364
- v.familyPosition = types_1.FamilyPosition.ROOT;
1407
+ v.parent = undefined;
1365
1408
  }
1366
1409
  this._root = v;
1367
1410
  };
@@ -6,12 +6,12 @@
6
6
  * @license MIT License
7
7
  */
8
8
  import { BST, BSTNode } from './bst';
9
- import type { AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId, RecursiveAVLTreeNode } from '../types';
9
+ import type { AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId } from '../types';
10
10
  import { IAVLTree, IAVLTreeNode } from '../interfaces';
11
- export declare class AVLTreeNode<T, FAMILY extends AVLTreeNode<T, FAMILY> = RecursiveAVLTreeNode<T>> extends BSTNode<T, FAMILY> implements IAVLTreeNode<T, FAMILY> {
11
+ export declare class AVLTreeNode<T = any, FAMILY extends AVLTreeNode<T, FAMILY> = AVLTreeNodeNested<T>> extends BSTNode<T, FAMILY> implements IAVLTreeNode<T, FAMILY> {
12
12
  createNode(id: BinaryTreeNodeId, val?: T, count?: number): FAMILY;
13
13
  }
14
- export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<number>> extends BST<N> implements IAVLTree<N> {
14
+ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends BST<N> implements IAVLTree<N> {
15
15
  constructor(options?: AVLTreeOptions);
16
16
  createNode(id: BinaryTreeNodeId, val?: N['val'], count?: number): N;
17
17
  /**
@@ -26,7 +26,7 @@ export declare class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode<nu
26
26
  * to `1`, indicating that the value should be inserted once.
27
27
  * @returns The method is returning either an N object or null.
28
28
  */
29
- add(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
29
+ add(id: BinaryTreeNodeId, val?: N['val'], count?: number): N | null;
30
30
  /**
31
31
  * The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
32
32
  * then balances the tree if necessary.
@@ -41,7 +41,7 @@ var AVLTreeNode = /** @class */ (function (_super) {
41
41
  return _super !== null && _super.apply(this, arguments) || this;
42
42
  }
43
43
  AVLTreeNode.prototype.createNode = function (id, val, count) {
44
- return new AVLTreeNode(id, (val === undefined ? id : val), count);
44
+ return new AVLTreeNode(id, val, count);
45
45
  };
46
46
  return AVLTreeNode;
47
47
  }(bst_1.BSTNode));
@@ -52,7 +52,7 @@ var AVLTree = /** @class */ (function (_super) {
52
52
  return _super.call(this, options) || this;
53
53
  }
54
54
  AVLTree.prototype.createNode = function (id, val, count) {
55
- return new AVLTreeNode(id, (val === undefined ? id : val), count);
55
+ return new AVLTreeNode(id, val, count);
56
56
  };
57
57
  /**
58
58
  * The function overrides the add method of a Binary Search Tree to insert a node with a given id and value, and then
@@ -5,11 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeNodeId, RecursiveBinaryTreeNode } from '../types';
8
+ import type { BinaryTreeNodeId, BinaryTreeNodeNested } from '../types';
9
9
  import { BinaryTreeOptions } from '../types';
10
10
  import { AbstractBinaryTree, AbstractBinaryTreeNode } from './abstract-binary-tree';
11
11
  import { IBinaryTree, IBinaryTreeNode } from '../interfaces/binary-tree';
12
- export declare class BinaryTreeNode<T = number, FAMILY extends BinaryTreeNode<T, FAMILY> = RecursiveBinaryTreeNode<T>> extends AbstractBinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
12
+ export declare class BinaryTreeNode<T = any, FAMILY extends BinaryTreeNode<T, FAMILY> = BinaryTreeNodeNested<T>> extends AbstractBinaryTreeNode<T, FAMILY> implements IBinaryTreeNode<T, FAMILY> {
13
13
  /**
14
14
  * The function creates a new binary tree node with an optional value and count, and returns it as a specified type.
15
15
  * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
@@ -25,7 +25,7 @@ export declare class BinaryTreeNode<T = number, FAMILY extends BinaryTreeNode<T,
25
25
  export declare class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode> extends AbstractBinaryTree<N> implements IBinaryTree<N> {
26
26
  /**
27
27
  * The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and
28
- * isDuplicatedVal based on the provided options.
28
+ * isMergeDuplicatedVal based on the provided options.
29
29
  * @param [options] - An optional object that can contain the following properties:
30
30
  */
31
31
  constructor(options?: BinaryTreeOptions);
@@ -40,7 +40,7 @@ var BinaryTreeNode = /** @class */ (function (_super) {
40
40
  * @returns a new instance of the BinaryTreeNode class, casted as the FAMILY type.
41
41
  */
42
42
  BinaryTreeNode.prototype.createNode = function (id, val, count) {
43
- return new BinaryTreeNode(id, (val === undefined ? id : val), count);
43
+ return new BinaryTreeNode(id, val, count);
44
44
  };
45
45
  return BinaryTreeNode;
46
46
  }(abstract_binary_tree_1.AbstractBinaryTreeNode));
@@ -49,11 +49,11 @@ var BinaryTree = /** @class */ (function (_super) {
49
49
  __extends(BinaryTree, _super);
50
50
  /**
51
51
  * The constructor function accepts an optional options object and sets the values of loopType, autoIncrementId, and
52
- * isDuplicatedVal based on the provided options.
52
+ * isMergeDuplicatedVal based on the provided options.
53
53
  * @param [options] - An optional object that can contain the following properties:
54
54
  */
55
55
  function BinaryTree(options) {
56
- return _super.call(this) || this;
56
+ return _super.call(this, options) || this;
57
57
  }
58
58
  /**
59
59
  * The function creates a new binary tree node with the given id, value, and count if the value is not null, otherwise
@@ -67,7 +67,7 @@ var BinaryTree = /** @class */ (function (_super) {
67
67
  * @returns a BinaryTreeNode object if the value is not null, otherwise it returns null.
68
68
  */
69
69
  BinaryTree.prototype.createNode = function (id, val, count) {
70
- return new BinaryTreeNode(id, val === undefined ? id : val, count);
70
+ return new BinaryTreeNode(id, val, count);
71
71
  };
72
72
  return BinaryTree;
73
73
  }(abstract_binary_tree_1.AbstractBinaryTree));