data-structure-typed 1.21.4 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (560) hide show
  1. package/.auto-changelog +9 -0
  2. package/.auto-changelog-template.hbs +36 -0
  3. package/.eslintrc.js +61 -0
  4. package/.github/workflows/ci.yml +30 -0
  5. package/.prettierignore +6 -0
  6. package/.prettierrc.js +16 -0
  7. package/CHANGELOG.md +17 -0
  8. package/README.md +147 -95
  9. package/dist/data-structures/binary-tree/aa-tree.js +6 -2
  10. package/dist/data-structures/binary-tree/aa-tree.js.map +1 -0
  11. package/dist/data-structures/binary-tree/abstract-binary-tree.js +398 -672
  12. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -0
  13. package/dist/data-structures/binary-tree/avl-tree.js +122 -151
  14. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -0
  15. package/dist/data-structures/binary-tree/b-tree.js +6 -2
  16. package/dist/data-structures/binary-tree/b-tree.js.map +1 -0
  17. package/dist/data-structures/binary-tree/binary-indexed-tree.js +24 -54
  18. package/dist/data-structures/binary-tree/binary-indexed-tree.js.map +1 -0
  19. package/dist/data-structures/binary-tree/binary-tree.js +31 -32
  20. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -0
  21. package/dist/data-structures/binary-tree/bst.js +266 -208
  22. package/dist/data-structures/binary-tree/bst.js.map +1 -0
  23. package/dist/data-structures/binary-tree/index.js +1 -0
  24. package/dist/data-structures/binary-tree/index.js.map +1 -0
  25. package/dist/data-structures/binary-tree/rb-tree.js +46 -37
  26. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -0
  27. package/dist/data-structures/binary-tree/segment-tree.js +124 -127
  28. package/dist/data-structures/binary-tree/segment-tree.js.map +1 -0
  29. package/dist/data-structures/binary-tree/splay-tree.js +6 -2
  30. package/dist/data-structures/binary-tree/splay-tree.js.map +1 -0
  31. package/dist/data-structures/binary-tree/tree-multiset.js +227 -354
  32. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -0
  33. package/dist/data-structures/binary-tree/two-three-tree.js +6 -2
  34. package/dist/data-structures/binary-tree/two-three-tree.js.map +1 -0
  35. package/dist/data-structures/graph/abstract-graph.js +582 -609
  36. package/dist/data-structures/graph/abstract-graph.js.map +1 -0
  37. package/dist/data-structures/graph/directed-graph.js +276 -312
  38. package/dist/data-structures/graph/directed-graph.js.map +1 -0
  39. package/dist/data-structures/graph/index.js +1 -0
  40. package/dist/data-structures/graph/index.js.map +1 -0
  41. package/dist/data-structures/graph/map-graph.js +88 -100
  42. package/dist/data-structures/graph/map-graph.js.map +1 -0
  43. package/dist/data-structures/graph/undirected-graph.js +180 -195
  44. package/dist/data-structures/graph/undirected-graph.js.map +1 -0
  45. package/dist/data-structures/hash/coordinate-map.js +46 -58
  46. package/dist/data-structures/hash/coordinate-map.js.map +1 -0
  47. package/dist/data-structures/hash/coordinate-set.js +43 -48
  48. package/dist/data-structures/hash/coordinate-set.js.map +1 -0
  49. package/dist/data-structures/hash/hash-table.js +6 -2
  50. package/dist/data-structures/hash/hash-table.js.map +1 -0
  51. package/dist/data-structures/hash/index.js +1 -0
  52. package/dist/data-structures/hash/index.js.map +1 -0
  53. package/dist/data-structures/hash/pair.js +6 -2
  54. package/dist/data-structures/hash/pair.js.map +1 -0
  55. package/dist/data-structures/hash/tree-map.js +6 -2
  56. package/dist/data-structures/hash/tree-map.js.map +1 -0
  57. package/dist/data-structures/hash/tree-set.js +6 -2
  58. package/dist/data-structures/hash/tree-set.js.map +1 -0
  59. package/dist/data-structures/heap/heap.js +83 -120
  60. package/dist/data-structures/heap/heap.js.map +1 -0
  61. package/dist/data-structures/heap/index.js +1 -0
  62. package/dist/data-structures/heap/index.js.map +1 -0
  63. package/dist/data-structures/heap/max-heap.js +27 -24
  64. package/dist/data-structures/heap/max-heap.js.map +1 -0
  65. package/dist/data-structures/heap/min-heap.js +27 -25
  66. package/dist/data-structures/heap/min-heap.js.map +1 -0
  67. package/dist/data-structures/index.js +1 -0
  68. package/dist/data-structures/index.js.map +1 -0
  69. package/dist/data-structures/linked-list/doubly-linked-list.js +202 -307
  70. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -0
  71. package/dist/data-structures/linked-list/index.js +1 -0
  72. package/dist/data-structures/linked-list/index.js.map +1 -0
  73. package/dist/data-structures/linked-list/singly-linked-list.js +223 -251
  74. package/dist/data-structures/linked-list/singly-linked-list.js.map +1 -0
  75. package/dist/data-structures/linked-list/skip-linked-list.js +6 -2
  76. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -0
  77. package/dist/data-structures/matrix/index.js +1 -0
  78. package/dist/data-structures/matrix/index.js.map +1 -0
  79. package/dist/data-structures/matrix/matrix.js +9 -22
  80. package/dist/data-structures/matrix/matrix.js.map +1 -0
  81. package/dist/data-structures/matrix/matrix2d.js +75 -149
  82. package/dist/data-structures/matrix/matrix2d.js.map +1 -0
  83. package/dist/data-structures/matrix/navigator.js +38 -46
  84. package/dist/data-structures/matrix/navigator.js.map +1 -0
  85. package/dist/data-structures/matrix/vector2d.js +90 -254
  86. package/dist/data-structures/matrix/vector2d.js.map +1 -0
  87. package/dist/data-structures/priority-queue/index.js +1 -0
  88. package/dist/data-structures/priority-queue/index.js.map +1 -0
  89. package/dist/data-structures/priority-queue/max-priority-queue.js +47 -32
  90. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -0
  91. package/dist/data-structures/priority-queue/min-priority-queue.js +47 -33
  92. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -0
  93. package/dist/data-structures/priority-queue/priority-queue.js +150 -241
  94. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -0
  95. package/dist/data-structures/queue/deque.js +130 -162
  96. package/dist/data-structures/queue/deque.js.map +1 -0
  97. package/dist/data-structures/queue/index.js +1 -0
  98. package/dist/data-structures/queue/index.js.map +1 -0
  99. package/dist/data-structures/queue/queue.js +181 -100
  100. package/dist/data-structures/queue/queue.js.map +1 -0
  101. package/dist/data-structures/stack/index.js +1 -0
  102. package/dist/data-structures/stack/index.js.map +1 -0
  103. package/dist/data-structures/stack/stack.js +23 -71
  104. package/dist/data-structures/stack/stack.js.map +1 -0
  105. package/dist/data-structures/tree/index.js +1 -0
  106. package/dist/data-structures/tree/index.js.map +1 -0
  107. package/dist/data-structures/tree/tree.js +46 -33
  108. package/dist/data-structures/tree/tree.js.map +1 -0
  109. package/dist/data-structures/trie/index.js +1 -0
  110. package/dist/data-structures/trie/index.js.map +1 -0
  111. package/dist/data-structures/trie/trie.js +201 -129
  112. package/dist/data-structures/trie/trie.js.map +1 -0
  113. package/dist/index.js +1 -0
  114. package/dist/index.js.map +1 -0
  115. package/dist/interfaces/abstract-binary-tree.js +1 -0
  116. package/dist/interfaces/abstract-binary-tree.js.map +1 -0
  117. package/dist/interfaces/abstract-graph.js +1 -0
  118. package/dist/interfaces/abstract-graph.js.map +1 -0
  119. package/dist/interfaces/avl-tree.js +1 -0
  120. package/dist/interfaces/avl-tree.js.map +1 -0
  121. package/dist/interfaces/binary-tree.js +1 -0
  122. package/dist/interfaces/binary-tree.js.map +1 -0
  123. package/dist/interfaces/bst.js +1 -0
  124. package/dist/interfaces/bst.js.map +1 -0
  125. package/dist/interfaces/directed-graph.js +1 -0
  126. package/dist/interfaces/directed-graph.js.map +1 -0
  127. package/dist/interfaces/doubly-linked-list.js +1 -0
  128. package/dist/interfaces/doubly-linked-list.js.map +1 -0
  129. package/dist/interfaces/heap.js +1 -0
  130. package/dist/interfaces/heap.js.map +1 -0
  131. package/dist/interfaces/index.js +1 -0
  132. package/dist/interfaces/index.js.map +1 -0
  133. package/dist/interfaces/navigator.js +1 -0
  134. package/dist/interfaces/navigator.js.map +1 -0
  135. package/dist/interfaces/priority-queue.js +1 -0
  136. package/dist/interfaces/priority-queue.js.map +1 -0
  137. package/dist/interfaces/rb-tree.js +1 -0
  138. package/dist/interfaces/rb-tree.js.map +1 -0
  139. package/dist/interfaces/segment-tree.js +1 -0
  140. package/dist/interfaces/segment-tree.js.map +1 -0
  141. package/dist/interfaces/singly-linked-list.js +1 -0
  142. package/dist/interfaces/singly-linked-list.js.map +1 -0
  143. package/dist/interfaces/tree-multiset.js +1 -0
  144. package/dist/interfaces/tree-multiset.js.map +1 -0
  145. package/dist/interfaces/undirected-graph.js +1 -0
  146. package/dist/interfaces/undirected-graph.js.map +1 -0
  147. package/dist/types/data-structures/abstract-binary-tree.js +1 -7
  148. package/dist/types/data-structures/abstract-binary-tree.js.map +1 -0
  149. package/dist/types/data-structures/abstract-graph.js +1 -0
  150. package/dist/types/data-structures/abstract-graph.js.map +1 -0
  151. package/dist/types/data-structures/avl-tree.js +1 -0
  152. package/dist/types/data-structures/avl-tree.js.map +1 -0
  153. package/dist/types/data-structures/binary-tree.js +1 -0
  154. package/dist/types/data-structures/binary-tree.js.map +1 -0
  155. package/dist/types/data-structures/bst.js +1 -0
  156. package/dist/types/data-structures/bst.js.map +1 -0
  157. package/dist/types/data-structures/directed-graph.js +1 -0
  158. package/dist/types/data-structures/directed-graph.js.map +1 -0
  159. package/dist/types/data-structures/doubly-linked-list.js +1 -0
  160. package/dist/types/data-structures/doubly-linked-list.js.map +1 -0
  161. package/dist/types/data-structures/heap.js +1 -0
  162. package/dist/types/data-structures/heap.js.map +1 -0
  163. package/dist/types/data-structures/index.js +1 -0
  164. package/dist/types/data-structures/index.js.map +1 -0
  165. package/dist/types/data-structures/map-graph.js +1 -0
  166. package/dist/types/data-structures/map-graph.js.map +1 -0
  167. package/dist/types/data-structures/navigator.js +1 -0
  168. package/dist/types/data-structures/navigator.js.map +1 -0
  169. package/dist/types/data-structures/priority-queue.js +1 -0
  170. package/dist/types/data-structures/priority-queue.js.map +1 -0
  171. package/dist/types/data-structures/rb-tree.js +1 -0
  172. package/dist/types/data-structures/rb-tree.js.map +1 -0
  173. package/dist/types/data-structures/segment-tree.js +1 -0
  174. package/dist/types/data-structures/segment-tree.js.map +1 -0
  175. package/dist/types/data-structures/singly-linked-list.js +1 -0
  176. package/dist/types/data-structures/singly-linked-list.js.map +1 -0
  177. package/dist/types/data-structures/tree-multiset.js +1 -0
  178. package/dist/types/data-structures/tree-multiset.js.map +1 -0
  179. package/dist/types/helpers.js +1 -0
  180. package/dist/types/helpers.js.map +1 -0
  181. package/dist/types/index.js +1 -0
  182. package/dist/types/index.js.map +1 -0
  183. package/dist/types/utils/index.js +1 -0
  184. package/dist/types/utils/index.js.map +1 -0
  185. package/dist/types/utils/utils.js +1 -0
  186. package/dist/types/utils/utils.js.map +1 -0
  187. package/dist/types/utils/validate-type.js +1 -0
  188. package/dist/types/utils/validate-type.js.map +1 -0
  189. package/dist/utils/index.js +1 -0
  190. package/dist/utils/index.js.map +1 -0
  191. package/dist/utils/utils.js +108 -22
  192. package/dist/utils/utils.js.map +1 -0
  193. package/docs/.nojekyll +1 -0
  194. package/docs/assets/highlight.css +127 -0
  195. package/docs/assets/main.js +58 -0
  196. package/docs/assets/search.js +1 -0
  197. package/docs/assets/style.css +1367 -0
  198. package/docs/classes/AVLTree.html +2259 -0
  199. package/docs/classes/AVLTreeNode.html +399 -0
  200. package/docs/classes/AaTree.html +202 -0
  201. package/docs/classes/AbstractBinaryTree.html +1913 -0
  202. package/docs/classes/AbstractBinaryTreeNode.html +441 -0
  203. package/docs/classes/AbstractEdge.html +345 -0
  204. package/docs/classes/AbstractGraph.html +1105 -0
  205. package/docs/classes/AbstractVertex.html +299 -0
  206. package/docs/classes/ArrayDeque.html +469 -0
  207. package/docs/classes/BST.html +2103 -0
  208. package/docs/classes/BSTNode.html +400 -0
  209. package/docs/classes/BTree.html +202 -0
  210. package/docs/classes/BinaryIndexedTree.html +371 -0
  211. package/docs/classes/BinaryTree.html +1944 -0
  212. package/docs/classes/BinaryTreeNode.html +399 -0
  213. package/docs/classes/Character.html +250 -0
  214. package/docs/classes/CoordinateMap.html +513 -0
  215. package/docs/classes/CoordinateSet.html +474 -0
  216. package/docs/classes/Deque.html +1005 -0
  217. package/docs/classes/DirectedEdge.html +404 -0
  218. package/docs/classes/DirectedGraph.html +1530 -0
  219. package/docs/classes/DirectedVertex.html +286 -0
  220. package/docs/classes/DoublyLinkedList.html +998 -0
  221. package/docs/classes/DoublyLinkedListNode.html +327 -0
  222. package/docs/classes/HashTable.html +202 -0
  223. package/docs/classes/Heap.html +647 -0
  224. package/docs/classes/HeapItem.html +296 -0
  225. package/docs/classes/LinkedListQueue.html +884 -0
  226. package/docs/classes/MapEdge.html +391 -0
  227. package/docs/classes/MapGraph.html +1583 -0
  228. package/docs/classes/MapVertex.html +356 -0
  229. package/docs/classes/Matrix2D.html +532 -0
  230. package/docs/classes/MatrixNTI2D.html +270 -0
  231. package/docs/classes/MaxHeap.html +671 -0
  232. package/docs/classes/MaxPriorityQueue.html +866 -0
  233. package/docs/classes/MinHeap.html +672 -0
  234. package/docs/classes/MinPriorityQueue.html +868 -0
  235. package/docs/classes/Navigator.html +343 -0
  236. package/docs/classes/ObjectDeque.html +527 -0
  237. package/docs/classes/Pair.html +202 -0
  238. package/docs/classes/PriorityQueue.html +790 -0
  239. package/docs/classes/Queue.html +521 -0
  240. package/docs/classes/RBTree.html +2101 -0
  241. package/docs/classes/RBTreeNode.html +431 -0
  242. package/docs/classes/SegmentTree.html +464 -0
  243. package/docs/classes/SegmentTreeNode.html +387 -0
  244. package/docs/classes/SinglyLinkedList.html +830 -0
  245. package/docs/classes/SinglyLinkedListNode.html +300 -0
  246. package/docs/classes/SkipLinkedList.html +202 -0
  247. package/docs/classes/SplayTree.html +202 -0
  248. package/docs/classes/Stack.html +398 -0
  249. package/docs/classes/TreeMap.html +202 -0
  250. package/docs/classes/TreeMultiset.html +2587 -0
  251. package/docs/classes/TreeMultisetNode.html +447 -0
  252. package/docs/classes/TreeNode.html +344 -0
  253. package/docs/classes/TreeSet.html +202 -0
  254. package/docs/classes/Trie.html +402 -0
  255. package/docs/classes/TrieNode.html +310 -0
  256. package/docs/classes/TwoThreeTree.html +202 -0
  257. package/docs/classes/UndirectedEdge.html +374 -0
  258. package/docs/classes/UndirectedGraph.html +1285 -0
  259. package/docs/classes/UndirectedVertex.html +284 -0
  260. package/docs/classes/Vector2D.html +835 -0
  261. package/docs/enums/CP.html +211 -0
  262. package/docs/enums/FamilyPosition.html +239 -0
  263. package/docs/enums/LoopType.html +212 -0
  264. package/docs/enums/RBColor.html +204 -0
  265. package/docs/enums/TopologicalProperty.html +211 -0
  266. package/docs/functions/arrayRemove.html +208 -0
  267. package/docs/functions/isThunk.html +186 -0
  268. package/docs/functions/toThunk.html +186 -0
  269. package/docs/functions/trampoline.html +186 -0
  270. package/docs/functions/trampolineAsync.html +186 -0
  271. package/docs/functions/uuidV4.html +181 -0
  272. package/docs/index.html +693 -0
  273. package/docs/interfaces/IAVLTree.html +1245 -0
  274. package/docs/interfaces/IAbstractBinaryTree.html +1101 -0
  275. package/docs/interfaces/IAbstractBinaryTreeNode.html +335 -0
  276. package/docs/interfaces/IAbstractGraph.html +433 -0
  277. package/docs/interfaces/IBST.html +1245 -0
  278. package/docs/interfaces/IDirectedGraph.html +570 -0
  279. package/docs/interfaces/IRBTree.html +1247 -0
  280. package/docs/interfaces/IUNDirectedGraph.html +463 -0
  281. package/docs/modules.html +328 -0
  282. package/docs/types/AVLTreeNodeNested.html +182 -0
  283. package/docs/types/AVLTreeOptions.html +180 -0
  284. package/docs/types/AbstractBinaryTreeNodeNested.html +182 -0
  285. package/docs/types/AbstractBinaryTreeNodeProperties.html +182 -0
  286. package/docs/types/AbstractBinaryTreeNodeProperty.html +182 -0
  287. package/docs/types/AbstractBinaryTreeOptions.html +182 -0
  288. package/docs/types/BSTComparator.html +192 -0
  289. package/docs/types/BSTNodeNested.html +182 -0
  290. package/docs/types/BSTOptions.html +182 -0
  291. package/docs/types/BinaryTreeDeletedResult.html +189 -0
  292. package/docs/types/BinaryTreeNodeId.html +177 -0
  293. package/docs/types/BinaryTreeNodeNested.html +182 -0
  294. package/docs/types/BinaryTreeNodePropertyName.html +177 -0
  295. package/docs/types/BinaryTreeOptions.html +180 -0
  296. package/docs/types/DFSOrderPattern.html +177 -0
  297. package/docs/types/DijkstraResult.html +199 -0
  298. package/docs/types/Direction.html +177 -0
  299. package/docs/types/DummyAny.html +190 -0
  300. package/docs/types/EdgeId.html +177 -0
  301. package/docs/types/HeapOptions.html +198 -0
  302. package/docs/types/IAVLTreeNode.html +184 -0
  303. package/docs/types/IBSTNode.html +184 -0
  304. package/docs/types/IBinaryTree.html +182 -0
  305. package/docs/types/IBinaryTreeNode.html +184 -0
  306. package/docs/types/IRBTreeNode.html +184 -0
  307. package/docs/types/ITreeMultiset.html +182 -0
  308. package/docs/types/ITreeMultisetNode.html +184 -0
  309. package/docs/types/KeyValueObject.html +182 -0
  310. package/docs/types/KeyValueObjectWithId.html +184 -0
  311. package/docs/types/MapGraphCoordinate.html +177 -0
  312. package/docs/types/NavigatorParams.html +211 -0
  313. package/docs/types/NodeOrPropertyName.html +177 -0
  314. package/docs/types/NonNumberNonObjectButDefined.html +177 -0
  315. package/docs/types/ObjectWithNonNumberId.html +184 -0
  316. package/docs/types/ObjectWithNumberId.html +184 -0
  317. package/docs/types/ObjectWithoutId.html +177 -0
  318. package/docs/types/PriorityQueueComparator.html +197 -0
  319. package/docs/types/PriorityQueueDFSOrderPattern.html +177 -0
  320. package/docs/types/PriorityQueueOptions.html +191 -0
  321. package/docs/types/RBTreeNodeNested.html +182 -0
  322. package/docs/types/RBTreeOptions.html +180 -0
  323. package/docs/types/RestrictValById.html +177 -0
  324. package/docs/types/SegmentTreeNodeVal.html +177 -0
  325. package/docs/types/SpecifyOptional.html +184 -0
  326. package/docs/types/Thunk.html +185 -0
  327. package/docs/types/ToThunkFn.html +185 -0
  328. package/docs/types/TopologicalStatus.html +177 -0
  329. package/docs/types/TreeMultisetNodeNested.html +182 -0
  330. package/docs/types/TreeMultisetOptions.html +180 -0
  331. package/docs/types/TrlAsyncFn.html +190 -0
  332. package/docs/types/TrlFn.html +190 -0
  333. package/docs/types/Turning.html +177 -0
  334. package/docs/types/VertexId.html +177 -0
  335. package/docs/variables/THUNK_SYMBOL.html +177 -0
  336. package/jest.config.js +5 -0
  337. package/lib/data-structures/binary-tree/aa-tree.js +2 -0
  338. package/{dist → lib}/data-structures/binary-tree/abstract-binary-tree.d.ts +25 -20
  339. package/lib/data-structures/binary-tree/abstract-binary-tree.js +1307 -0
  340. package/{dist → lib}/data-structures/binary-tree/avl-tree.d.ts +12 -12
  341. package/lib/data-structures/binary-tree/avl-tree.js +311 -0
  342. package/lib/data-structures/binary-tree/b-tree.js +2 -0
  343. package/lib/data-structures/binary-tree/binary-indexed-tree.js +69 -0
  344. package/lib/data-structures/binary-tree/binary-tree.js +35 -0
  345. package/{dist → lib}/data-structures/binary-tree/bst.d.ts +19 -8
  346. package/lib/data-structures/binary-tree/bst.js +551 -0
  347. package/lib/data-structures/binary-tree/index.js +12 -0
  348. package/{dist → lib}/data-structures/binary-tree/rb-tree.d.ts +0 -6
  349. package/lib/data-structures/binary-tree/rb-tree.js +22 -0
  350. package/lib/data-structures/binary-tree/segment-tree.js +210 -0
  351. package/lib/data-structures/binary-tree/splay-tree.js +2 -0
  352. package/{dist → lib}/data-structures/binary-tree/tree-multiset.d.ts +20 -23
  353. package/lib/data-structures/binary-tree/tree-multiset.js +673 -0
  354. package/lib/data-structures/binary-tree/two-three-tree.js +2 -0
  355. package/lib/data-structures/graph/abstract-graph.js +918 -0
  356. package/lib/data-structures/graph/directed-graph.js +416 -0
  357. package/lib/data-structures/graph/index.js +4 -0
  358. package/lib/data-structures/graph/map-graph.js +105 -0
  359. package/lib/data-structures/graph/undirected-graph.js +246 -0
  360. package/lib/data-structures/hash/coordinate-map.js +61 -0
  361. package/lib/data-structures/hash/coordinate-set.js +51 -0
  362. package/lib/data-structures/hash/hash-table.js +2 -0
  363. package/lib/data-structures/hash/index.js +6 -0
  364. package/lib/data-structures/hash/pair.js +2 -0
  365. package/lib/data-structures/hash/tree-map.js +2 -0
  366. package/lib/data-structures/hash/tree-set.js +2 -0
  367. package/lib/data-structures/heap/heap.js +152 -0
  368. package/lib/data-structures/heap/index.js +3 -0
  369. package/lib/data-structures/heap/max-heap.js +26 -0
  370. package/lib/data-structures/heap/min-heap.js +27 -0
  371. package/lib/data-structures/index.js +11 -0
  372. package/{dist → lib}/data-structures/linked-list/doubly-linked-list.d.ts +5 -5
  373. package/lib/data-structures/linked-list/doubly-linked-list.js +521 -0
  374. package/lib/data-structures/linked-list/index.js +3 -0
  375. package/{dist → lib}/data-structures/linked-list/singly-linked-list.d.ts +6 -5
  376. package/lib/data-structures/linked-list/singly-linked-list.js +443 -0
  377. package/lib/data-structures/linked-list/skip-linked-list.js +2 -0
  378. package/lib/data-structures/matrix/index.js +4 -0
  379. package/lib/data-structures/matrix/matrix.js +24 -0
  380. package/lib/data-structures/matrix/matrix2d.js +195 -0
  381. package/lib/data-structures/matrix/navigator.js +101 -0
  382. package/lib/data-structures/matrix/vector2d.js +287 -0
  383. package/lib/data-structures/priority-queue/index.js +3 -0
  384. package/lib/data-structures/priority-queue/max-priority-queue.js +39 -0
  385. package/lib/data-structures/priority-queue/min-priority-queue.js +40 -0
  386. package/lib/data-structures/priority-queue/priority-queue.js +317 -0
  387. package/{dist → lib}/data-structures/queue/deque.d.ts +45 -0
  388. package/lib/data-structures/queue/deque.js +270 -0
  389. package/lib/data-structures/queue/index.js +2 -0
  390. package/{dist → lib}/data-structures/queue/queue.d.ts +47 -13
  391. package/lib/data-structures/queue/queue.js +165 -0
  392. package/lib/data-structures/stack/index.js +1 -0
  393. package/lib/data-structures/stack/stack.js +87 -0
  394. package/lib/data-structures/tree/index.js +1 -0
  395. package/lib/data-structures/tree/tree.js +56 -0
  396. package/lib/data-structures/trie/index.js +1 -0
  397. package/lib/data-structures/trie/trie.js +205 -0
  398. package/lib/index.js +4 -0
  399. package/{dist → lib}/interfaces/avl-tree.d.ts +1 -9
  400. package/lib/interfaces/binary-tree.d.ts +4 -0
  401. package/{dist → lib}/interfaces/bst.d.ts +1 -2
  402. package/lib/interfaces/heap.js +1 -0
  403. package/lib/interfaces/index.js +15 -0
  404. package/lib/interfaces/navigator.d.ts +1 -0
  405. package/lib/interfaces/navigator.js +1 -0
  406. package/lib/interfaces/priority-queue.d.ts +1 -0
  407. package/lib/interfaces/priority-queue.js +1 -0
  408. package/{dist → lib}/interfaces/rb-tree.d.ts +1 -2
  409. package/lib/interfaces/rb-tree.js +1 -0
  410. package/lib/interfaces/segment-tree.d.ts +1 -0
  411. package/lib/interfaces/segment-tree.js +1 -0
  412. package/lib/interfaces/singly-linked-list.d.ts +1 -0
  413. package/lib/interfaces/singly-linked-list.js +1 -0
  414. package/lib/interfaces/tree-multiset.d.ts +5 -0
  415. package/lib/interfaces/tree-multiset.js +1 -0
  416. package/lib/interfaces/undirected-graph.js +1 -0
  417. package/{dist → lib}/types/data-structures/abstract-binary-tree.d.ts +1 -1
  418. package/lib/types/data-structures/abstract-binary-tree.js +22 -0
  419. package/lib/types/data-structures/abstract-graph.js +1 -0
  420. package/{dist → lib}/types/data-structures/avl-tree.d.ts +1 -1
  421. package/lib/types/data-structures/avl-tree.js +1 -0
  422. package/lib/types/data-structures/binary-tree.js +1 -0
  423. package/lib/types/data-structures/bst.js +6 -0
  424. package/lib/types/data-structures/directed-graph.js +6 -0
  425. package/lib/types/data-structures/doubly-linked-list.d.ts +1 -0
  426. package/lib/types/data-structures/doubly-linked-list.js +1 -0
  427. package/lib/types/data-structures/heap.js +1 -0
  428. package/lib/types/data-structures/index.js +15 -0
  429. package/lib/types/data-structures/map-graph.js +1 -0
  430. package/lib/types/data-structures/navigator.js +1 -0
  431. package/lib/types/data-structures/priority-queue.js +1 -0
  432. package/lib/types/data-structures/rb-tree.js +5 -0
  433. package/lib/types/data-structures/segment-tree.js +1 -0
  434. package/lib/types/data-structures/singly-linked-list.d.ts +1 -0
  435. package/lib/types/data-structures/singly-linked-list.js +1 -0
  436. package/lib/types/data-structures/tree-multiset.js +1 -0
  437. package/lib/types/helpers.d.ts +1 -0
  438. package/lib/types/helpers.js +1 -0
  439. package/lib/types/index.js +3 -0
  440. package/lib/types/utils/index.js +2 -0
  441. package/{dist → lib}/types/utils/utils.d.ts +1 -1
  442. package/lib/types/utils/utils.js +1 -0
  443. package/{dist → lib}/types/utils/validate-type.d.ts +1 -1
  444. package/lib/types/utils/validate-type.js +1 -0
  445. package/lib/utils/index.js +1 -0
  446. package/lib/utils/utils.js +57 -0
  447. package/package.json +147 -56
  448. package/rename_clear_files.sh +29 -0
  449. package/test/integration/avl-tree.test.ts +111 -0
  450. package/test/integration/bst.test.ts +371 -0
  451. package/test/integration/heap.test.js +19 -0
  452. package/test/integration/index.html +44 -0
  453. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +111 -0
  454. package/test/unit/data-structures/binary-tree/bst.test.ts +371 -0
  455. package/test/unit/data-structures/binary-tree/overall.test.ts +57 -0
  456. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +405 -0
  457. package/test/unit/data-structures/graph/abstract-graph.test.ts +5 -0
  458. package/test/unit/data-structures/graph/directed-graph.test.ts +517 -0
  459. package/test/unit/data-structures/graph/index.ts +2 -0
  460. package/test/unit/data-structures/graph/map-graph.test.ts +46 -0
  461. package/test/unit/data-structures/graph/overall.test.ts +50 -0
  462. package/test/unit/data-structures/graph/undirected-graph.test.ts +60 -0
  463. package/test/unit/data-structures/heap/heap.test.ts +56 -0
  464. package/test/unit/data-structures/heap/max-heap.test.ts +42 -0
  465. package/test/unit/data-structures/heap/min-heap.test.ts +81 -0
  466. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +365 -0
  467. package/test/unit/data-structures/linked-list/index.ts +4 -0
  468. package/test/unit/data-structures/linked-list/linked-list.test.ts +37 -0
  469. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +401 -0
  470. package/test/unit/data-structures/linked-list/skip-linked-list.test.ts +13 -0
  471. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +106 -0
  472. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +105 -0
  473. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +27 -0
  474. package/test/unit/data-structures/queue/queue.test.ts +36 -0
  475. package/test/utils/index.ts +2 -0
  476. package/test/utils/magnitude.ts +21 -0
  477. package/test/utils/number.ts +3 -0
  478. package/tsconfig.build.json +33 -0
  479. package/tsconfig.json +38 -0
  480. package/umd/bundle.min.js +3 -0
  481. package/umd/bundle.min.js.map +1 -0
  482. package/webpack.config.js +28 -0
  483. package/dist/bundle.js +0 -2
  484. package/dist/interfaces/binary-tree.d.ts +0 -6
  485. package/dist/interfaces/tree-multiset.d.ts +0 -7
  486. /package/{dist → lib}/data-structures/binary-tree/aa-tree.d.ts +0 -0
  487. /package/{dist → lib}/data-structures/binary-tree/b-tree.d.ts +0 -0
  488. /package/{dist → lib}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  489. /package/{dist → lib}/data-structures/binary-tree/binary-tree.d.ts +0 -0
  490. /package/{dist → lib}/data-structures/binary-tree/index.d.ts +0 -0
  491. /package/{dist → lib}/data-structures/binary-tree/segment-tree.d.ts +0 -0
  492. /package/{dist → lib}/data-structures/binary-tree/splay-tree.d.ts +0 -0
  493. /package/{dist → lib}/data-structures/binary-tree/two-three-tree.d.ts +0 -0
  494. /package/{dist → lib}/data-structures/graph/abstract-graph.d.ts +0 -0
  495. /package/{dist → lib}/data-structures/graph/directed-graph.d.ts +0 -0
  496. /package/{dist → lib}/data-structures/graph/index.d.ts +0 -0
  497. /package/{dist → lib}/data-structures/graph/map-graph.d.ts +0 -0
  498. /package/{dist → lib}/data-structures/graph/undirected-graph.d.ts +0 -0
  499. /package/{dist → lib}/data-structures/hash/coordinate-map.d.ts +0 -0
  500. /package/{dist → lib}/data-structures/hash/coordinate-set.d.ts +0 -0
  501. /package/{dist → lib}/data-structures/hash/hash-table.d.ts +0 -0
  502. /package/{dist → lib}/data-structures/hash/index.d.ts +0 -0
  503. /package/{dist → lib}/data-structures/hash/pair.d.ts +0 -0
  504. /package/{dist → lib}/data-structures/hash/tree-map.d.ts +0 -0
  505. /package/{dist → lib}/data-structures/hash/tree-set.d.ts +0 -0
  506. /package/{dist → lib}/data-structures/heap/heap.d.ts +0 -0
  507. /package/{dist → lib}/data-structures/heap/index.d.ts +0 -0
  508. /package/{dist → lib}/data-structures/heap/max-heap.d.ts +0 -0
  509. /package/{dist → lib}/data-structures/heap/min-heap.d.ts +0 -0
  510. /package/{dist → lib}/data-structures/index.d.ts +0 -0
  511. /package/{dist → lib}/data-structures/linked-list/index.d.ts +0 -0
  512. /package/{dist → lib}/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  513. /package/{dist → lib}/data-structures/matrix/index.d.ts +0 -0
  514. /package/{dist → lib}/data-structures/matrix/matrix.d.ts +0 -0
  515. /package/{dist → lib}/data-structures/matrix/matrix2d.d.ts +0 -0
  516. /package/{dist → lib}/data-structures/matrix/navigator.d.ts +0 -0
  517. /package/{dist → lib}/data-structures/matrix/vector2d.d.ts +0 -0
  518. /package/{dist → lib}/data-structures/priority-queue/index.d.ts +0 -0
  519. /package/{dist → lib}/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  520. /package/{dist → lib}/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  521. /package/{dist → lib}/data-structures/priority-queue/priority-queue.d.ts +0 -0
  522. /package/{dist → lib}/data-structures/queue/index.d.ts +0 -0
  523. /package/{dist → lib}/data-structures/stack/index.d.ts +0 -0
  524. /package/{dist → lib}/data-structures/stack/stack.d.ts +0 -0
  525. /package/{dist → lib}/data-structures/tree/index.d.ts +0 -0
  526. /package/{dist → lib}/data-structures/tree/tree.d.ts +0 -0
  527. /package/{dist → lib}/data-structures/trie/index.d.ts +0 -0
  528. /package/{dist → lib}/data-structures/trie/trie.d.ts +0 -0
  529. /package/{dist → lib}/index.d.ts +0 -0
  530. /package/{dist → lib}/interfaces/abstract-binary-tree.d.ts +0 -0
  531. /package/{dist/interfaces/doubly-linked-list.d.ts → lib/interfaces/abstract-binary-tree.js} +0 -0
  532. /package/{dist → lib}/interfaces/abstract-graph.d.ts +0 -0
  533. /package/{dist/interfaces/heap.d.ts → lib/interfaces/abstract-graph.js} +0 -0
  534. /package/{dist/interfaces/navigator.d.ts → lib/interfaces/avl-tree.js} +0 -0
  535. /package/{dist/interfaces/priority-queue.d.ts → lib/interfaces/binary-tree.js} +0 -0
  536. /package/{dist/interfaces/segment-tree.d.ts → lib/interfaces/bst.js} +0 -0
  537. /package/{dist → lib}/interfaces/directed-graph.d.ts +0 -0
  538. /package/{dist/interfaces/singly-linked-list.d.ts → lib/interfaces/directed-graph.js} +0 -0
  539. /package/{dist/types/data-structures → lib/interfaces}/doubly-linked-list.d.ts +0 -0
  540. /package/{dist/types/data-structures/singly-linked-list.d.ts → lib/interfaces/doubly-linked-list.js} +0 -0
  541. /package/{dist/types/helpers.d.ts → lib/interfaces/heap.d.ts} +0 -0
  542. /package/{dist → lib}/interfaces/index.d.ts +0 -0
  543. /package/{dist → lib}/interfaces/undirected-graph.d.ts +0 -0
  544. /package/{dist → lib}/types/data-structures/abstract-graph.d.ts +0 -0
  545. /package/{dist → lib}/types/data-structures/binary-tree.d.ts +0 -0
  546. /package/{dist → lib}/types/data-structures/bst.d.ts +0 -0
  547. /package/{dist → lib}/types/data-structures/directed-graph.d.ts +0 -0
  548. /package/{dist → lib}/types/data-structures/heap.d.ts +0 -0
  549. /package/{dist → lib}/types/data-structures/index.d.ts +0 -0
  550. /package/{dist → lib}/types/data-structures/map-graph.d.ts +0 -0
  551. /package/{dist → lib}/types/data-structures/navigator.d.ts +0 -0
  552. /package/{dist → lib}/types/data-structures/priority-queue.d.ts +0 -0
  553. /package/{dist → lib}/types/data-structures/rb-tree.d.ts +0 -0
  554. /package/{dist → lib}/types/data-structures/segment-tree.d.ts +0 -0
  555. /package/{dist → lib}/types/data-structures/tree-multiset.d.ts +0 -0
  556. /package/{dist → lib}/types/index.d.ts +0 -0
  557. /package/{dist → lib}/types/utils/index.d.ts +0 -0
  558. /package/{dist → lib}/utils/index.d.ts +0 -0
  559. /package/{dist → lib}/utils/utils.d.ts +0 -0
  560. /package/{dist/bundle.js.LICENSE.txt → umd/bundle.min.js.LICENSE.txt} +0 -0
@@ -1,70 +1,91 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TreeMultiset = exports.TreeMultisetNode = void 0;
4
- const types_1 = require("../../types");
5
- const avl_tree_1 = require("./avl-tree");
6
- class TreeMultisetNode extends avl_tree_1.AVLTreeNode {
7
- /**
8
- * The constructor function initializes a BinaryTreeNode object with an id, value, and count.
9
- * @param {BinaryTreeNodeId} id - The `id` parameter is of type `BinaryTreeNodeId` and represents the unique identifier
10
- * of the binary tree node.
11
- * @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value of the binary
12
- * tree node. If no value is provided, it will be `undefined`.
13
- * @param {number} [count=1] - The `count` parameter is a number that represents the number of times a particular value
14
- * occurs in a binary tree node. It has a default value of 1, which means that if no value is provided for the `count`
15
- * parameter when creating a new instance of the `BinaryTreeNode` class,
16
- */
17
- constructor(id, val, count = 1) {
18
- super(id, val);
19
- this._count = count;
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __read = (this && this.__read) || function (o, n) {
29
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
30
+ if (!m) return o;
31
+ var i = m.call(o), r, ar = [], e;
32
+ try {
33
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
20
34
  }
21
- get count() {
22
- return this._count;
35
+ catch (error) { e = { error: error }; }
36
+ finally {
37
+ try {
38
+ if (r && !r.done && (m = i["return"])) m.call(i);
39
+ }
40
+ finally { if (e) throw e.error; }
23
41
  }
24
- set count(v) {
25
- this._count = v;
42
+ return ar;
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.TreeMultiset = exports.TreeMultisetNode = void 0;
46
+ var types_1 = require("../../types");
47
+ var avl_tree_1 = require("./avl-tree");
48
+ var TreeMultisetNode = (function (_super) {
49
+ __extends(TreeMultisetNode, _super);
50
+ function TreeMultisetNode(id, val, count) {
51
+ if (count === void 0) { count = 1; }
52
+ var _this = _super.call(this, id, val) || this;
53
+ _this._count = count;
54
+ return _this;
26
55
  }
27
- }
56
+ Object.defineProperty(TreeMultisetNode.prototype, "count", {
57
+ get: function () {
58
+ return this._count;
59
+ },
60
+ set: function (v) {
61
+ this._count = v;
62
+ },
63
+ enumerable: false,
64
+ configurable: true
65
+ });
66
+ return TreeMultisetNode;
67
+ }(avl_tree_1.AVLTreeNode));
28
68
  exports.TreeMultisetNode = TreeMultisetNode;
29
- /**
30
- * The only distinction between a TreeMultiset and a AVLTree lies in the ability of the former to store duplicate nodes through the utilization of counters.
31
- */
32
- class TreeMultiset extends avl_tree_1.AVLTree {
33
- /**
34
- * The constructor function for a TreeMultiset class in TypeScript, which extends another class and sets an option to
35
- * merge duplicated values.
36
- * @param {TreeMultisetOptions} [options] - An optional object that contains additional configuration options for the
37
- * TreeMultiset.
38
- */
39
- constructor(options) {
40
- super(Object.assign({}, options));
41
- this._count = 0;
42
- }
43
- get count() {
44
- return this._count;
69
+ var TreeMultiset = (function (_super) {
70
+ __extends(TreeMultiset, _super);
71
+ function TreeMultiset(options) {
72
+ var _this = _super.call(this, __assign({}, options)) || this;
73
+ _this._count = 0;
74
+ return _this;
45
75
  }
46
- /**
47
- * The function creates a new BSTNode with the given id, value, and count.
48
- * @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
49
- * distinguish one node from another in the tree.
50
- * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
51
- * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
52
- * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
53
- * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
54
- */
55
- createNode(id, val, count) {
76
+ Object.defineProperty(TreeMultiset.prototype, "count", {
77
+ get: function () {
78
+ return this._count;
79
+ },
80
+ enumerable: false,
81
+ configurable: true
82
+ });
83
+ TreeMultiset.prototype.createNode = function (id, val, count) {
56
84
  return new TreeMultisetNode(id, val, count);
57
- }
58
- /**
59
- * The function swaps the location of two nodes in a tree data structure.
60
- * @param {N} srcNode - The source node that we want to swap with the destination node.
61
- * @param {N} destNode - The `destNode` parameter represents the destination node where the values from `srcNode` will
62
- * be swapped with.
63
- * @returns the `destNode` after swapping its values with the `srcNode`.
64
- */
65
- swapLocation(srcNode, destNode) {
66
- const { id, val, count, height } = destNode;
67
- const tempNode = this.createNode(id, val, count);
85
+ };
86
+ TreeMultiset.prototype.swapLocation = function (srcNode, destNode) {
87
+ var id = destNode.id, val = destNode.val, count = destNode.count, height = destNode.height;
88
+ var tempNode = this.createNode(id, val, count);
68
89
  if (tempNode) {
69
90
  tempNode.height = height;
70
91
  destNode.id = srcNode.id;
@@ -77,20 +98,10 @@ class TreeMultiset extends avl_tree_1.AVLTree {
77
98
  srcNode.height = tempNode.height;
78
99
  }
79
100
  return destNode;
80
- }
81
- /**
82
- * The `add` function adds a new node to a binary search tree, maintaining the tree's properties and balancing if
83
- * necessary.
84
- * @param {BinaryTreeNodeId | N} idOrNode - The `idOrNode` parameter can be either a `BinaryTreeNodeId` or a `N` (which
85
- * represents a `BinaryTreeNode`).
86
- * @param [val] - The `val` parameter represents the value to be added to the binary tree node.
87
- * @param {number} [count] - The `count` parameter is an optional parameter that specifies the number of times the
88
- * value should be added to the binary tree. If the `count` parameter is not provided, it defaults to 1.
89
- * @returns The method `add` returns either the inserted node (`N`), `null`, or `undefined`.
90
- */
91
- add(idOrNode, val, count) {
101
+ };
102
+ TreeMultiset.prototype.add = function (idOrNode, val, count) {
92
103
  count = count !== null && count !== void 0 ? count : 1;
93
- let inserted = undefined, newNode;
104
+ var inserted = undefined, newNode;
94
105
  if (idOrNode instanceof TreeMultisetNode) {
95
106
  newNode = this.createNode(idOrNode.id, idOrNode.val, idOrNode.count);
96
107
  }
@@ -107,8 +118,8 @@ class TreeMultiset extends avl_tree_1.AVLTree {
107
118
  inserted = this.root;
108
119
  }
109
120
  else {
110
- let cur = this.root;
111
- let traversing = true;
121
+ var cur = this.root;
122
+ var traversing = true;
112
123
  while (traversing) {
113
124
  if (cur) {
114
125
  if (newNode) {
@@ -120,9 +131,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
120
131
  inserted = cur;
121
132
  }
122
133
  else if (this._compare(cur.id, newNode.id) === types_1.CP.gt) {
123
- // Traverse left of the node
124
134
  if (cur.left === undefined) {
125
- //Add to the left of the current node
126
135
  cur.left = newNode;
127
136
  this._setSize(this.size + 1);
128
137
  this._setCount(this.count + newNode.count);
@@ -130,30 +139,25 @@ class TreeMultiset extends avl_tree_1.AVLTree {
130
139
  inserted = cur.left;
131
140
  }
132
141
  else {
133
- //Traverse the left of the current node
134
142
  if (cur.left)
135
143
  cur = cur.left;
136
144
  }
137
145
  }
138
146
  else if (this._compare(cur.id, newNode.id) === types_1.CP.lt) {
139
- // Traverse right of the node
140
147
  if (cur.right === undefined) {
141
- //Add to the right of the current node
142
148
  cur.right = newNode;
143
149
  this._setSize(this.size + 1);
144
150
  this._setCount(this.count + newNode.count);
145
151
  traversing = false;
146
- inserted = (cur.right);
152
+ inserted = cur.right;
147
153
  }
148
154
  else {
149
- //Traverse the left of the current node
150
155
  if (cur.right)
151
156
  cur = cur.right;
152
157
  }
153
158
  }
154
159
  }
155
160
  else {
156
- // TODO may need to support null inserted
157
161
  }
158
162
  }
159
163
  else {
@@ -162,19 +166,10 @@ class TreeMultiset extends avl_tree_1.AVLTree {
162
166
  }
163
167
  }
164
168
  if (inserted)
165
- this.balancePath(inserted);
169
+ this._balancePath(inserted);
166
170
  return inserted;
167
- }
168
- /**
169
- * The function adds a new node to a binary tree if there is an available slot on the left or right side of the parent
170
- * node.
171
- * @param {N | null} newNode - The `newNode` parameter represents the node that needs to be added to the tree. It can
172
- * be either a node object (`N`) or `null`.
173
- * @param {N} parent - The `parent` parameter represents the parent node to which the new node will be added as a
174
- * child.
175
- * @returns The method returns either the `parent.left`, `parent.right`, or `undefined`.
176
- */
177
- _addTo(newNode, parent) {
171
+ };
172
+ TreeMultiset.prototype._addTo = function (newNode, parent) {
178
173
  if (parent) {
179
174
  if (parent.left === undefined) {
180
175
  parent.left = newNode;
@@ -199,72 +194,51 @@ class TreeMultiset extends avl_tree_1.AVLTree {
199
194
  else {
200
195
  return;
201
196
  }
202
- }
203
- /**
204
- * The `addMany` function adds multiple nodes to a binary tree and returns an array of the inserted nodes.
205
- * @param {BinaryTreeNodeId[] | N[]} idsOrNodes - An array of BinaryTreeNodeId objects or N objects. These objects
206
- * represent the IDs or nodes of the binary tree where the values will be added.
207
- * @param {N['val'][]} [data] - Optional array of values to be associated with each node being added. If provided, the
208
- * length of the `data` array should be equal to the length of the `idsOrNodes` array.
209
- * @returns The function `addMany` returns an array of `N`, `null`, or `undefined` values.
210
- */
211
- addMany(idsOrNodes, data) {
212
- var _a;
213
- // TODO not sure addMany not be run multi times
214
- const inserted = [];
215
- const map = new Map();
216
- for (const idOrNode of idsOrNodes)
217
- map.set(idOrNode, ((_a = map.get(idOrNode)) !== null && _a !== void 0 ? _a : 0) + 1);
218
- for (let i = 0; i < idsOrNodes.length; i++) {
219
- const idOrNode = idsOrNodes[i];
220
- if (map.has(idOrNode)) {
221
- if (idOrNode instanceof TreeMultisetNode) {
222
- inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
223
- continue;
224
- }
225
- if (idOrNode === null) {
226
- inserted.push(this.add(NaN, null, 0));
227
- continue;
228
- }
229
- const val = data === null || data === void 0 ? void 0 : data[i], count = map.get(idOrNode);
230
- inserted.push(this.add(idOrNode, val, count));
231
- map.delete(idOrNode);
197
+ };
198
+ TreeMultiset.prototype.addMany = function (idsOrNodes, data) {
199
+ var inserted = [];
200
+ for (var i = 0; i < idsOrNodes.length; i++) {
201
+ var idOrNode = idsOrNodes[i];
202
+ if (idOrNode instanceof TreeMultisetNode) {
203
+ inserted.push(this.add(idOrNode.id, idOrNode.val, idOrNode.count));
204
+ continue;
232
205
  }
206
+ if (idOrNode === null) {
207
+ inserted.push(this.add(NaN, null, 0));
208
+ continue;
209
+ }
210
+ inserted.push(this.add(idOrNode, data === null || data === void 0 ? void 0 : data[i], 1));
233
211
  }
234
212
  return inserted;
235
- }
236
- /**
237
- * The `perfectlyBalance` function takes a binary tree, performs a depth-first search to sort the nodes, and then
238
- * constructs a balanced binary search tree using either a recursive or iterative approach.
239
- * @returns The function `perfectlyBalance()` returns a boolean value.
240
- */
241
- perfectlyBalance() {
242
- const sorted = this.DFS('in', 'node'), n = sorted.length;
213
+ };
214
+ TreeMultiset.prototype.perfectlyBalance = function () {
215
+ var _this = this;
216
+ var sorted = this.DFS('in', 'node'), n = sorted.length;
243
217
  if (sorted.length < 1)
244
218
  return false;
245
219
  this.clear();
246
220
  if (this.loopType === types_1.LoopType.RECURSIVE) {
247
- const buildBalanceBST = (l, r) => {
221
+ var buildBalanceBST_1 = function (l, r) {
248
222
  if (l > r)
249
223
  return;
250
- const m = l + Math.floor((r - l) / 2);
251
- const midNode = sorted[m];
252
- this.add(midNode.id, midNode.val, midNode.count);
253
- buildBalanceBST(l, m - 1);
254
- buildBalanceBST(m + 1, r);
224
+ var m = l + Math.floor((r - l) / 2);
225
+ var midNode = sorted[m];
226
+ _this.add(midNode.id, midNode.val, midNode.count);
227
+ buildBalanceBST_1(l, m - 1);
228
+ buildBalanceBST_1(m + 1, r);
255
229
  };
256
- buildBalanceBST(0, n - 1);
230
+ buildBalanceBST_1(0, n - 1);
257
231
  return true;
258
232
  }
259
233
  else {
260
- const stack = [[0, n - 1]];
234
+ var stack = [[0, n - 1]];
261
235
  while (stack.length > 0) {
262
- const popped = stack.pop();
236
+ var popped = stack.pop();
263
237
  if (popped) {
264
- const [l, r] = popped;
238
+ var _a = __read(popped, 2), l = _a[0], r = _a[1];
265
239
  if (l <= r) {
266
- const m = l + Math.floor((r - l) / 2);
267
- const midNode = sorted[m];
240
+ var m = l + Math.floor((r - l) / 2);
241
+ var midNode = sorted[m];
268
242
  this.add(midNode.id, midNode.val, midNode.count);
269
243
  stack.push([m + 1, r]);
270
244
  stack.push([l, m - 1]);
@@ -273,25 +247,16 @@ class TreeMultiset extends avl_tree_1.AVLTree {
273
247
  }
274
248
  return true;
275
249
  }
276
- }
277
- /**
278
- * The `remove` function removes a node from a binary search tree and returns the deleted node along with the parent
279
- * node that needs to be balanced.
280
- * @param {N | BinaryTreeNodeId | null} nodeOrId - The `nodeOrId` parameter can be one of the following:
281
- * @param {boolean} [ignoreCount] - The `ignoreCount` parameter is an optional boolean parameter that determines
282
- * whether to ignore the count of the node being removed. If `ignoreCount` is set to `true`, the count of the node will
283
- * not be taken into account when removing it. If `ignoreCount` is set to `false
284
- * @returns The function `remove` returns an array of `BinaryTreeDeletedResult<N>` objects.
285
- */
286
- remove(nodeOrId, ignoreCount) {
287
- const bstDeletedResult = [];
250
+ };
251
+ TreeMultiset.prototype.remove = function (nodeOrId, ignoreCount) {
252
+ var bstDeletedResult = [];
288
253
  if (!this.root)
289
254
  return bstDeletedResult;
290
- const curr = this.get(nodeOrId);
255
+ var curr = this.get(nodeOrId);
291
256
  if (!curr)
292
257
  return bstDeletedResult;
293
- const parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
294
- let needBalanced = null, orgCurrent = curr;
258
+ var parent = (curr === null || curr === void 0 ? void 0 : curr.parent) ? curr.parent : null;
259
+ var needBalanced = null, orgCurrent = curr;
295
260
  if (curr.count > 1 && !ignoreCount) {
296
261
  curr.count--;
297
262
  this._setCount(this.count - 1);
@@ -303,7 +268,7 @@ class TreeMultiset extends avl_tree_1.AVLTree {
303
268
  this._setRoot(curr.right);
304
269
  }
305
270
  else {
306
- const { familyPosition: fp } = curr;
271
+ var fp = curr.familyPosition;
307
272
  if (fp === types_1.FamilyPosition.LEFT || fp === types_1.FamilyPosition.ROOT_LEFT) {
308
273
  parent.left = curr.right;
309
274
  }
@@ -314,9 +279,9 @@ class TreeMultiset extends avl_tree_1.AVLTree {
314
279
  }
315
280
  }
316
281
  else {
317
- const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
282
+ var leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
318
283
  if (leftSubTreeRightMost) {
319
- const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
284
+ var parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
320
285
  orgCurrent = this.swapLocation(curr, leftSubTreeRightMost);
321
286
  if (parentOfLeftSubTreeMax) {
322
287
  if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) {
@@ -330,40 +295,32 @@ class TreeMultiset extends avl_tree_1.AVLTree {
330
295
  }
331
296
  }
332
297
  this._setSize(this.size - 1);
333
- // TODO How to handle when the count of target node is lesser than current node's count
334
298
  this._setCount(this.count - orgCurrent.count);
335
299
  }
336
- bstDeletedResult.push({ deleted: orgCurrent, needBalanced });
300
+ bstDeletedResult.push({ deleted: orgCurrent, needBalanced: needBalanced });
337
301
  if (needBalanced) {
338
- this.balancePath(needBalanced);
302
+ this._balancePath(needBalanced);
339
303
  }
340
304
  return bstDeletedResult;
341
- }
342
- /**
343
- * The function `getSubTreeCount` calculates the number of nodes and the sum of their counts in a subtree, using either
344
- * recursive or iterative traversal.
345
- * @param {N | null | undefined} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree in a
346
- * binary tree.
347
- * @returns The function `getSubTreeCount` returns an array `[number, number]`.
348
- */
349
- getSubTreeCount(subTreeRoot) {
350
- const res = [0, 0];
305
+ };
306
+ TreeMultiset.prototype.getSubTreeCount = function (subTreeRoot) {
307
+ var res = [0, 0];
351
308
  if (!subTreeRoot)
352
309
  return res;
353
310
  if (this.loopType === types_1.LoopType.RECURSIVE) {
354
- const _traverse = (cur) => {
311
+ var _traverse_1 = function (cur) {
355
312
  res[0]++;
356
313
  res[1] += cur.count;
357
- cur.left && _traverse(cur.left);
358
- cur.right && _traverse(cur.right);
314
+ cur.left && _traverse_1(cur.left);
315
+ cur.right && _traverse_1(cur.right);
359
316
  };
360
- _traverse(subTreeRoot);
317
+ _traverse_1(subTreeRoot);
361
318
  return res;
362
319
  }
363
320
  else {
364
- const stack = [subTreeRoot];
321
+ var stack = [subTreeRoot];
365
322
  while (stack.length > 0) {
366
- const cur = stack.pop();
323
+ var cur = stack.pop();
367
324
  res[0]++;
368
325
  res[1] += cur.count;
369
326
  cur.right && stack.push(cur.right);
@@ -371,94 +328,67 @@ class TreeMultiset extends avl_tree_1.AVLTree {
371
328
  }
372
329
  return res;
373
330
  }
374
- }
375
- /**
376
- * The function `subTreeSumCount` calculates the sum of the `count` property of each node in a subtree, either
377
- * recursively or iteratively.
378
- * @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
379
- * in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree) or
380
- * `null` if the subtree is empty.
381
- * @returns the sum of the count values of all nodes in the subtree rooted at `subTreeRoot`.
382
- */
383
- subTreeSumCount(subTreeRoot) {
331
+ };
332
+ TreeMultiset.prototype.subTreeSumCount = function (subTreeRoot) {
384
333
  if (typeof subTreeRoot === 'number')
385
334
  subTreeRoot = this.get(subTreeRoot, 'id');
386
335
  if (!subTreeRoot)
387
336
  return 0;
388
- let sum = 0;
337
+ var sum = 0;
389
338
  if (this.loopType === types_1.LoopType.RECURSIVE) {
390
- const _traverse = (cur) => {
339
+ var _traverse_2 = function (cur) {
391
340
  sum += cur.count;
392
- cur.left && _traverse(cur.left);
393
- cur.right && _traverse(cur.right);
341
+ cur.left && _traverse_2(cur.left);
342
+ cur.right && _traverse_2(cur.right);
394
343
  };
395
- _traverse(subTreeRoot);
344
+ _traverse_2(subTreeRoot);
396
345
  }
397
346
  else {
398
- const stack = [subTreeRoot];
347
+ var stack = [subTreeRoot];
399
348
  while (stack.length > 0) {
400
- const cur = stack.pop();
349
+ var cur = stack.pop();
401
350
  sum += cur.count;
402
351
  cur.right && stack.push(cur.right);
403
352
  cur.left && stack.push(cur.left);
404
353
  }
405
354
  }
406
355
  return sum;
407
- }
408
- /**
409
- * The function `subTreeAddCount` recursively or iteratively traverses a binary tree and adds a given delta value to
410
- * the `count` property of each node.
411
- * @param {N | BinaryTreeNodeId | null} subTreeRoot - The `subTreeRoot` parameter represents the root node of a subtree
412
- * in a binary tree. It can be either a `BinaryTreeNodeId` (a unique identifier for a node in the binary tree), a
413
- * `BinaryTreeNode` object, or `null` if the subtree is empty.
414
- * @param {number} delta - The delta parameter is a number that represents the amount by which the count of each node
415
- * in the subtree should be increased or decreased.
416
- * @returns a boolean value.
417
- */
418
- subTreeAddCount(subTreeRoot, delta) {
356
+ };
357
+ TreeMultiset.prototype.subTreeAddCount = function (subTreeRoot, delta) {
358
+ var _this = this;
419
359
  if (typeof subTreeRoot === 'number')
420
360
  subTreeRoot = this.get(subTreeRoot, 'id');
421
361
  if (!subTreeRoot)
422
362
  return false;
423
- const _addByProperty = (cur) => {
363
+ var _addByProperty = function (cur) {
424
364
  cur.count += delta;
425
- this._setCount(this.count + delta);
365
+ _this._setCount(_this.count + delta);
426
366
  };
427
367
  if (this.loopType === types_1.LoopType.RECURSIVE) {
428
- const _traverse = (cur) => {
368
+ var _traverse_3 = function (cur) {
429
369
  _addByProperty(cur);
430
- cur.left && _traverse(cur.left);
431
- cur.right && _traverse(cur.right);
370
+ cur.left && _traverse_3(cur.left);
371
+ cur.right && _traverse_3(cur.right);
432
372
  };
433
- _traverse(subTreeRoot);
373
+ _traverse_3(subTreeRoot);
434
374
  }
435
375
  else {
436
- const stack = [subTreeRoot];
376
+ var stack = [subTreeRoot];
437
377
  while (stack.length > 0) {
438
- const cur = stack.pop();
378
+ var cur = stack.pop();
439
379
  _addByProperty(cur);
440
380
  cur.right && stack.push(cur.right);
441
381
  cur.left && stack.push(cur.left);
442
382
  }
443
383
  }
444
384
  return true;
445
- }
446
- /**
447
- * The function `getNodesByCount` returns an array of nodes that have a specific count property, either recursively or
448
- * using a queue.
449
- * @param {BinaryTreeNodeId | N} nodeProperty - The `nodeProperty` parameter can be either a `BinaryTreeNodeId` or a
450
- * `N`. It represents the property of the nodes that you want to search for.
451
- * @param {boolean} [onlyOne] - The `onlyOne` parameter is an optional boolean parameter that determines whether to
452
- * return only one node that matches the `nodeProperty` or all nodes that match the `nodeProperty`. If `onlyOne` is set
453
- * to `true`, the function will return only one node. If `onlyOne`
454
- * @returns an array of nodes that match the given nodeProperty.
455
- */
456
- getNodesByCount(nodeProperty, onlyOne) {
385
+ };
386
+ TreeMultiset.prototype.getNodesByCount = function (nodeProperty, onlyOne) {
457
387
  if (!this.root)
458
388
  return [];
459
- const result = [];
389
+ var result = [];
460
390
  if (this.loopType === types_1.LoopType.RECURSIVE) {
461
- const _traverse = (cur) => {
391
+ var _traverse_4 = function (cur) {
462
392
  if (cur.count === nodeProperty) {
463
393
  result.push(cur);
464
394
  if (onlyOne)
@@ -466,15 +396,15 @@ class TreeMultiset extends avl_tree_1.AVLTree {
466
396
  }
467
397
  if (!cur.left && !cur.right)
468
398
  return;
469
- cur.left && _traverse(cur.left);
470
- cur.right && _traverse(cur.right);
399
+ cur.left && _traverse_4(cur.left);
400
+ cur.right && _traverse_4(cur.right);
471
401
  };
472
- _traverse(this.root);
402
+ _traverse_4(this.root);
473
403
  }
474
404
  else {
475
- const queue = [this.root];
405
+ var queue = [this.root];
476
406
  while (queue.length > 0) {
477
- const cur = queue.shift();
407
+ var cur = queue.shift();
478
408
  if (cur) {
479
409
  if (cur.count === nodeProperty) {
480
410
  result.push(cur);
@@ -487,123 +417,78 @@ class TreeMultiset extends avl_tree_1.AVLTree {
487
417
  }
488
418
  }
489
419
  return result;
490
- }
491
- /**
492
- * The BFSCount function returns an array of counts from a breadth-first search of nodes.
493
- * @returns The BFSCount() function returns an array of numbers, specifically the count property of each node in the
494
- * BFS traversal.
495
- */
496
- BFSCount() {
497
- const nodes = super.BFS('node');
498
- return nodes.map(node => node.count);
499
- }
500
- /**
501
- * The function "listLevelsCount" takes a node and returns an array of arrays, where each inner array contains the
502
- * count property of each node at that level.
503
- * @param {N | null} node - The parameter `node` is of type `N | null`. This means that it can either be an instance of
504
- * the class `N` or `null`.
505
- * @returns a 2D array of numbers. Each inner array represents a level in the binary tree, and each number in the inner
506
- * array represents the count property of a node in that level.
507
- */
508
- listLevelsCount(node) {
509
- const levels = super.listLevels(node, 'node');
510
- return levels.map(level => level.map(node => node.count));
511
- }
512
- /**
513
- * The `morrisCount` function returns an array of counts for each node in a binary tree, based on a specified traversal
514
- * pattern.
515
- * @param {'in' | 'pre' | 'post'} [pattern] - The `pattern` parameter is an optional parameter that specifies the
516
- * traversal pattern for the Morris traversal algorithm. It can have one of three values: 'in', 'pre', or 'post'.
517
- * @returns The function `morrisCount` returns an array of numbers.
518
- */
519
- morrisCount(pattern) {
420
+ };
421
+ TreeMultiset.prototype.BFSCount = function () {
422
+ var nodes = _super.prototype.BFS.call(this, 'node');
423
+ return nodes.map(function (node) { return node.count; });
424
+ };
425
+ TreeMultiset.prototype.listLevelsCount = function (node) {
426
+ var levels = _super.prototype.listLevels.call(this, node, 'node');
427
+ return levels.map(function (level) { return level.map(function (node) { return node.count; }); });
428
+ };
429
+ TreeMultiset.prototype.morrisCount = function (pattern) {
520
430
  pattern = pattern || 'in';
521
- const nodes = super.morris(pattern, 'node');
522
- return nodes.map(node => node.count);
523
- }
524
- /**
525
- * The function DFSIterativeCount performs a depth-first search iteratively and returns an array of count values for
526
- * each node.
527
- * @param {'in' | 'pre' | 'post'} [pattern] - The "pattern" parameter is a string that specifies the traversal order
528
- * for the Depth-First Search (DFS) algorithm. It can have one of three values: 'in', 'pre', or 'post'.
529
- * @param {NodeOrPropertyName} [nodeOrPropertyName] - The `nodeOrPropertyName` parameter is an optional parameter that
530
- * specifies whether to return the nodes or the property names during the depth-first search traversal. If it is set to
531
- * `'node'`, the function will return the nodes. If it is set to `'property'`, the function will return the property
532
- * @returns The DFSIterativeCount method returns an array of numbers.
533
- */
534
- DFSIterativeCount(pattern, nodeOrPropertyName) {
431
+ var nodes = _super.prototype.morris.call(this, pattern, 'node');
432
+ return nodes.map(function (node) { return node.count; });
433
+ };
434
+ TreeMultiset.prototype.DFSIterativeCount = function (pattern) {
535
435
  pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
536
- const nodes = super.DFSIterative(pattern, 'node');
537
- return nodes.map(node => node.count);
538
- }
539
- /**
540
- * The DFSCount function returns an array of counts for each node in a depth-first search traversal.
541
- * @param {DFSOrderPattern} [pattern] - The `pattern` parameter is an optional parameter that specifies the order in
542
- * which the Depth-First Search (DFS) algorithm should traverse the nodes. It can have one of the following values:
543
- * @param [nodeOrPropertyName] - The parameter `nodeOrPropertyName` is used to specify whether you want to retrieve the
544
- * nodes themselves or a specific property of the nodes. If you pass `'count'` as the value for `nodeOrPropertyName`,
545
- * the function will return an array of the `count` property of each node.
546
- * @returns The DFSCount method returns an array of numbers representing the count property of each node in the DFS
547
- * traversal.
548
- */
549
- DFSCount(pattern, nodeOrPropertyName) {
436
+ var nodes = _super.prototype.DFSIterative.call(this, pattern, 'node');
437
+ return nodes.map(function (node) { return node.count; });
438
+ };
439
+ TreeMultiset.prototype.DFSCount = function (pattern) {
550
440
  pattern = pattern !== null && pattern !== void 0 ? pattern : 'in';
551
- const nodes = super.DFS(pattern, 'node');
552
- return nodes.map(node => node.count);
553
- }
554
- /**
555
- * The `lesserSumCount` function calculates the sum of the counts of all nodes in a binary tree that have a lesser
556
- * value than a given node.
557
- * @param {N | BinaryTreeNodeId | null} beginNode - The `beginNode` parameter can be one of the following:
558
- * @returns the sum of the counts of nodes in the binary tree that have a lesser value than the given beginNode.
559
- */
560
- lesserSumCount(beginNode) {
441
+ var nodes = _super.prototype.DFS.call(this, pattern, 'node');
442
+ return nodes.map(function (node) { return node.count; });
443
+ };
444
+ TreeMultiset.prototype.lesserSumCount = function (beginNode) {
445
+ var _this = this;
561
446
  if (typeof beginNode === 'number')
562
447
  beginNode = this.get(beginNode, 'id');
563
448
  if (!beginNode)
564
449
  return 0;
565
450
  if (!this.root)
566
451
  return 0;
567
- const id = beginNode.id;
568
- let sum = 0;
452
+ var id = beginNode.id;
453
+ var sum = 0;
569
454
  if (this.loopType === types_1.LoopType.RECURSIVE) {
570
- const _traverse = (cur) => {
571
- const compared = this._compare(cur.id, id);
455
+ var _traverse_5 = function (cur) {
456
+ var compared = _this._compare(cur.id, id);
572
457
  if (compared === types_1.CP.eq) {
573
458
  if (cur.right)
574
- sum += this.subTreeSumCount(cur.right);
459
+ sum += _this.subTreeSumCount(cur.right);
575
460
  return;
576
461
  }
577
462
  else if (compared === types_1.CP.lt) {
578
463
  if (cur.left)
579
- sum += this.subTreeSumCount(cur.left);
464
+ sum += _this.subTreeSumCount(cur.left);
580
465
  sum += cur.count;
581
466
  if (cur.right)
582
- _traverse(cur.right);
467
+ _traverse_5(cur.right);
583
468
  else
584
469
  return;
585
470
  }
586
471
  else {
587
472
  if (cur.left)
588
- _traverse(cur.left);
473
+ _traverse_5(cur.left);
589
474
  else
590
475
  return;
591
476
  }
592
477
  };
593
- _traverse(this.root);
478
+ _traverse_5(this.root);
594
479
  }
595
480
  else {
596
- const queue = [this.root];
481
+ var queue = [this.root];
597
482
  while (queue.length > 0) {
598
- const cur = queue.shift();
483
+ var cur = queue.shift();
599
484
  if (cur) {
600
- const compared = this._compare(cur.id, id);
485
+ var compared = this._compare(cur.id, id);
601
486
  if (compared === types_1.CP.eq) {
602
487
  if (cur.right)
603
488
  sum += this.subTreeSumCount(cur.right);
604
489
  return sum;
605
490
  }
606
- else if (compared === types_1.CP.lt) { // todo maybe a bug
491
+ else if (compared === types_1.CP.lt) {
607
492
  if (cur.left)
608
493
  sum += this.subTreeSumCount(cur.left);
609
494
  sum += cur.count;
@@ -622,44 +507,37 @@ class TreeMultiset extends avl_tree_1.AVLTree {
622
507
  }
623
508
  }
624
509
  return sum;
625
- }
626
- /**
627
- * The function `allGreaterNodesAddCount` updates the count property of all nodes in a binary tree that have an ID
628
- * greater than a given ID by a specified delta value.
629
- * @param {N | BinaryTreeNodeId | null} node - The `node` parameter can be one of the following:
630
- * @param {number} delta - The `delta` parameter is a number that represents the amount by which the `count` property
631
- * of each node should be increased.
632
- * @returns a boolean value.
633
- */
634
- allGreaterNodesAddCount(node, delta) {
510
+ };
511
+ TreeMultiset.prototype.allGreaterNodesAddCount = function (node, delta) {
512
+ var _this = this;
635
513
  if (typeof node === 'number')
636
514
  node = this.get(node, 'id');
637
515
  if (!node)
638
516
  return false;
639
- const id = node.id;
517
+ var id = node.id;
640
518
  if (!this.root)
641
519
  return false;
642
520
  if (this.loopType === types_1.LoopType.RECURSIVE) {
643
- const _traverse = (cur) => {
644
- const compared = this._compare(cur.id, id);
521
+ var _traverse_6 = function (cur) {
522
+ var compared = _this._compare(cur.id, id);
645
523
  if (compared === types_1.CP.gt)
646
524
  cur.count += delta;
647
525
  if (!cur.left && !cur.right)
648
526
  return;
649
- if (cur.left && this._compare(cur.left.id, id) === types_1.CP.gt)
650
- _traverse(cur.left);
651
- if (cur.right && this._compare(cur.right.id, id) === types_1.CP.gt)
652
- _traverse(cur.right);
527
+ if (cur.left && _this._compare(cur.left.id, id) === types_1.CP.gt)
528
+ _traverse_6(cur.left);
529
+ if (cur.right && _this._compare(cur.right.id, id) === types_1.CP.gt)
530
+ _traverse_6(cur.right);
653
531
  };
654
- _traverse(this.root);
532
+ _traverse_6(this.root);
655
533
  return true;
656
534
  }
657
535
  else {
658
- const queue = [this.root];
536
+ var queue = [this.root];
659
537
  while (queue.length > 0) {
660
- const cur = queue.shift();
538
+ var cur = queue.shift();
661
539
  if (cur) {
662
- const compared = this._compare(cur.id, id);
540
+ var compared = this._compare(cur.id, id);
663
541
  if (compared === types_1.CP.gt)
664
542
  cur.count += delta;
665
543
  if (cur.left && this._compare(cur.left.id, id) === types_1.CP.gt)
@@ -670,20 +548,15 @@ class TreeMultiset extends avl_tree_1.AVLTree {
670
548
  }
671
549
  return true;
672
550
  }
673
- }
674
- /**
675
- * The clear() function clears the data and sets the count to 0.
676
- */
677
- clear() {
678
- super.clear();
551
+ };
552
+ TreeMultiset.prototype.clear = function () {
553
+ _super.prototype.clear.call(this);
679
554
  this._setCount(0);
680
- }
681
- /**
682
- * The function "_setCount" is used to set the value of the "_count" property.
683
- * @param {number} v - number
684
- */
685
- _setCount(v) {
555
+ };
556
+ TreeMultiset.prototype._setCount = function (v) {
686
557
  this._count = v;
687
- }
688
- }
558
+ };
559
+ return TreeMultiset;
560
+ }(avl_tree_1.AVLTree));
689
561
  exports.TreeMultiset = TreeMultiset;
562
+ //# sourceMappingURL=tree-multiset.js.map