data-structure-typed 1.32.1 → 1.32.9

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 (342) hide show
  1. package/.idea/data-structure-typed.iml +19 -0
  2. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  3. package/.idea/misc.xml +6 -0
  4. package/.idea/modules.xml +8 -0
  5. package/.idea/vcs.xml +6 -0
  6. package/CHANGELOG.md +1 -1
  7. package/README.md +415 -255
  8. package/coverage/coverage-final.json +4 -4
  9. package/docs/index.html +268 -21
  10. package/package.json +48 -16
  11. package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +46 -1
  12. package/.auto-changelog-template.hbs +0 -36
  13. package/coverage/clover.xml +0 -3393
  14. package/coverage/lcov-report/base.css +0 -224
  15. package/coverage/lcov-report/block-navigation.js +0 -87
  16. package/coverage/lcov-report/favicon.png +0 -0
  17. package/coverage/lcov-report/index.html +0 -386
  18. package/coverage/lcov-report/prettify.css +0 -1
  19. package/coverage/lcov-report/prettify.js +0 -2
  20. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  21. package/coverage/lcov-report/sorter.js +0 -196
  22. package/coverage/lcov-report/src/data-structures/binary-tree/aa-tree.ts.html +0 -88
  23. package/coverage/lcov-report/src/data-structures/binary-tree/abstract-binary-tree.ts.html +0 -4978
  24. package/coverage/lcov-report/src/data-structures/binary-tree/avl-tree.ts.html +0 -1015
  25. package/coverage/lcov-report/src/data-structures/binary-tree/b-tree.ts.html +0 -88
  26. package/coverage/lcov-report/src/data-structures/binary-tree/binary-indexed-tree.ts.html +0 -313
  27. package/coverage/lcov-report/src/data-structures/binary-tree/binary-tree.ts.html +0 -226
  28. package/coverage/lcov-report/src/data-structures/binary-tree/bst.ts.html +0 -1696
  29. package/coverage/lcov-report/src/data-structures/binary-tree/index.html +0 -296
  30. package/coverage/lcov-report/src/data-structures/binary-tree/index.ts.html +0 -121
  31. package/coverage/lcov-report/src/data-structures/binary-tree/rb-tree.ts.html +0 -388
  32. package/coverage/lcov-report/src/data-structures/binary-tree/segment-tree.ts.html +0 -811
  33. package/coverage/lcov-report/src/data-structures/binary-tree/splay-tree.ts.html +0 -88
  34. package/coverage/lcov-report/src/data-structures/binary-tree/tree-multiset.ts.html +0 -2185
  35. package/coverage/lcov-report/src/data-structures/binary-tree/two-three-tree.ts.html +0 -88
  36. package/coverage/lcov-report/src/data-structures/graph/abstract-graph.ts.html +0 -3205
  37. package/coverage/lcov-report/src/data-structures/graph/directed-graph.ts.html +0 -1495
  38. package/coverage/lcov-report/src/data-structures/graph/index.html +0 -176
  39. package/coverage/lcov-report/src/data-structures/graph/index.ts.html +0 -97
  40. package/coverage/lcov-report/src/data-structures/graph/map-graph.ts.html +0 -472
  41. package/coverage/lcov-report/src/data-structures/graph/undirected-graph.ts.html +0 -907
  42. package/coverage/lcov-report/src/data-structures/hash/coordinate-map.ts.html +0 -286
  43. package/coverage/lcov-report/src/data-structures/hash/coordinate-set.ts.html +0 -253
  44. package/coverage/lcov-report/src/data-structures/hash/hash-table.ts.html +0 -88
  45. package/coverage/lcov-report/src/data-structures/hash/index.html +0 -206
  46. package/coverage/lcov-report/src/data-structures/hash/index.ts.html +0 -103
  47. package/coverage/lcov-report/src/data-structures/hash/pair.ts.html +0 -88
  48. package/coverage/lcov-report/src/data-structures/hash/tree-map.ts.html +0 -88
  49. package/coverage/lcov-report/src/data-structures/hash/tree-set.ts.html +0 -88
  50. package/coverage/lcov-report/src/data-structures/heap/heap.ts.html +0 -721
  51. package/coverage/lcov-report/src/data-structures/heap/index.html +0 -161
  52. package/coverage/lcov-report/src/data-structures/heap/index.ts.html +0 -94
  53. package/coverage/lcov-report/src/data-structures/heap/max-heap.ts.html +0 -178
  54. package/coverage/lcov-report/src/data-structures/heap/min-heap.ts.html +0 -181
  55. package/coverage/lcov-report/src/data-structures/index.html +0 -116
  56. package/coverage/lcov-report/src/data-structures/index.ts.html +0 -118
  57. package/coverage/lcov-report/src/data-structures/linked-list/doubly-linked-list.ts.html +0 -1804
  58. package/coverage/lcov-report/src/data-structures/linked-list/index.html +0 -161
  59. package/coverage/lcov-report/src/data-structures/linked-list/index.ts.html +0 -94
  60. package/coverage/lcov-report/src/data-structures/linked-list/singly-linked-list.ts.html +0 -1588
  61. package/coverage/lcov-report/src/data-structures/linked-list/skip-linked-list.ts.html +0 -88
  62. package/coverage/lcov-report/src/data-structures/matrix/index.html +0 -176
  63. package/coverage/lcov-report/src/data-structures/matrix/index.ts.html +0 -97
  64. package/coverage/lcov-report/src/data-structures/matrix/matrix.ts.html +0 -166
  65. package/coverage/lcov-report/src/data-structures/matrix/matrix2d.ts.html +0 -721
  66. package/coverage/lcov-report/src/data-structures/matrix/navigator.ts.html +0 -448
  67. package/coverage/lcov-report/src/data-structures/matrix/vector2d.ts.html +0 -1033
  68. package/coverage/lcov-report/src/data-structures/priority-queue/index.html +0 -161
  69. package/coverage/lcov-report/src/data-structures/priority-queue/index.ts.html +0 -94
  70. package/coverage/lcov-report/src/data-structures/priority-queue/max-priority-queue.ts.html +0 -253
  71. package/coverage/lcov-report/src/data-structures/priority-queue/min-priority-queue.ts.html +0 -256
  72. package/coverage/lcov-report/src/data-structures/priority-queue/priority-queue.ts.html +0 -1162
  73. package/coverage/lcov-report/src/data-structures/queue/deque.ts.html +0 -976
  74. package/coverage/lcov-report/src/data-structures/queue/index.html +0 -146
  75. package/coverage/lcov-report/src/data-structures/queue/index.ts.html +0 -91
  76. package/coverage/lcov-report/src/data-structures/queue/queue.ts.html +0 -658
  77. package/coverage/lcov-report/src/data-structures/stack/index.html +0 -131
  78. package/coverage/lcov-report/src/data-structures/stack/index.ts.html +0 -88
  79. package/coverage/lcov-report/src/data-structures/stack/stack.ts.html +0 -379
  80. package/coverage/lcov-report/src/data-structures/tree/index.html +0 -131
  81. package/coverage/lcov-report/src/data-structures/tree/index.ts.html +0 -88
  82. package/coverage/lcov-report/src/data-structures/tree/tree.ts.html +0 -292
  83. package/coverage/lcov-report/src/data-structures/trie/index.html +0 -131
  84. package/coverage/lcov-report/src/data-structures/trie/index.ts.html +0 -88
  85. package/coverage/lcov-report/src/data-structures/trie/trie.ts.html +0 -760
  86. package/coverage/lcov-report/src/index.html +0 -116
  87. package/coverage/lcov-report/src/index.ts.html +0 -97
  88. package/coverage/lcov-report/src/interfaces/index.html +0 -116
  89. package/coverage/lcov-report/src/interfaces/index.ts.html +0 -130
  90. package/coverage/lcov-report/src/types/data-structures/abstract-binary-tree.ts.html +0 -235
  91. package/coverage/lcov-report/src/types/data-structures/bst.ts.html +0 -124
  92. package/coverage/lcov-report/src/types/data-structures/directed-graph.ts.html +0 -109
  93. package/coverage/lcov-report/src/types/data-structures/index.html +0 -176
  94. package/coverage/lcov-report/src/types/data-structures/index.ts.html +0 -130
  95. package/coverage/lcov-report/src/types/data-structures/rb-tree.ts.html +0 -106
  96. package/coverage/lcov-report/src/types/index.html +0 -116
  97. package/coverage/lcov-report/src/types/index.ts.html +0 -94
  98. package/coverage/lcov-report/src/types/utils/index.html +0 -116
  99. package/coverage/lcov-report/src/types/utils/index.ts.html +0 -91
  100. package/coverage/lcov-report/src/utils/index.html +0 -131
  101. package/coverage/lcov-report/src/utils/index.ts.html +0 -88
  102. package/coverage/lcov-report/src/utils/utils.ts.html +0 -322
  103. package/coverage/lcov-report/test/utils/index.html +0 -146
  104. package/coverage/lcov-report/test/utils/index.ts.html +0 -91
  105. package/coverage/lcov-report/test/utils/magnitude.ts.html +0 -148
  106. package/coverage/lcov-report/test/utils/number.ts.html +0 -94
  107. package/coverage/lcov.info +0 -6676
  108. package/docs/assets/highlight.css +0 -127
  109. package/docs/assets/main.js +0 -58
  110. package/docs/assets/search.js +0 -1
  111. package/docs/assets/style.css +0 -1367
  112. package/docs/classes/AVLTree.html +0 -2182
  113. package/docs/classes/AVLTreeNode.html +0 -399
  114. package/docs/classes/AaTree.html +0 -202
  115. package/docs/classes/AbstractBinaryTree.html +0 -1836
  116. package/docs/classes/AbstractBinaryTreeNode.html +0 -441
  117. package/docs/classes/AbstractEdge.html +0 -345
  118. package/docs/classes/AbstractGraph.html +0 -1105
  119. package/docs/classes/AbstractVertex.html +0 -299
  120. package/docs/classes/ArrayDeque.html +0 -469
  121. package/docs/classes/BST.html +0 -2026
  122. package/docs/classes/BSTNode.html +0 -400
  123. package/docs/classes/BTree.html +0 -202
  124. package/docs/classes/BinaryIndexedTree.html +0 -371
  125. package/docs/classes/BinaryTree.html +0 -1867
  126. package/docs/classes/BinaryTreeNode.html +0 -399
  127. package/docs/classes/Character.html +0 -250
  128. package/docs/classes/CoordinateMap.html +0 -513
  129. package/docs/classes/CoordinateSet.html +0 -474
  130. package/docs/classes/Deque.html +0 -1005
  131. package/docs/classes/DirectedEdge.html +0 -404
  132. package/docs/classes/DirectedGraph.html +0 -1530
  133. package/docs/classes/DirectedVertex.html +0 -286
  134. package/docs/classes/DoublyLinkedList.html +0 -998
  135. package/docs/classes/DoublyLinkedListNode.html +0 -327
  136. package/docs/classes/HashTable.html +0 -202
  137. package/docs/classes/Heap.html +0 -647
  138. package/docs/classes/HeapItem.html +0 -296
  139. package/docs/classes/LinkedListQueue.html +0 -884
  140. package/docs/classes/MapEdge.html +0 -391
  141. package/docs/classes/MapGraph.html +0 -1583
  142. package/docs/classes/MapVertex.html +0 -356
  143. package/docs/classes/Matrix2D.html +0 -532
  144. package/docs/classes/MatrixNTI2D.html +0 -270
  145. package/docs/classes/MaxHeap.html +0 -671
  146. package/docs/classes/MaxPriorityQueue.html +0 -866
  147. package/docs/classes/MinHeap.html +0 -672
  148. package/docs/classes/MinPriorityQueue.html +0 -868
  149. package/docs/classes/Navigator.html +0 -343
  150. package/docs/classes/ObjectDeque.html +0 -527
  151. package/docs/classes/Pair.html +0 -202
  152. package/docs/classes/PriorityQueue.html +0 -790
  153. package/docs/classes/Queue.html +0 -521
  154. package/docs/classes/RBTree.html +0 -2024
  155. package/docs/classes/RBTreeNode.html +0 -431
  156. package/docs/classes/SegmentTree.html +0 -464
  157. package/docs/classes/SegmentTreeNode.html +0 -387
  158. package/docs/classes/SinglyLinkedList.html +0 -830
  159. package/docs/classes/SinglyLinkedListNode.html +0 -300
  160. package/docs/classes/SkipLinkedList.html +0 -202
  161. package/docs/classes/SplayTree.html +0 -202
  162. package/docs/classes/Stack.html +0 -398
  163. package/docs/classes/TreeMap.html +0 -202
  164. package/docs/classes/TreeMultiset.html +0 -2510
  165. package/docs/classes/TreeMultisetNode.html +0 -447
  166. package/docs/classes/TreeNode.html +0 -344
  167. package/docs/classes/TreeSet.html +0 -202
  168. package/docs/classes/Trie.html +0 -402
  169. package/docs/classes/TrieNode.html +0 -310
  170. package/docs/classes/TwoThreeTree.html +0 -202
  171. package/docs/classes/UndirectedEdge.html +0 -374
  172. package/docs/classes/UndirectedGraph.html +0 -1285
  173. package/docs/classes/UndirectedVertex.html +0 -284
  174. package/docs/classes/Vector2D.html +0 -835
  175. package/docs/enums/CP.html +0 -211
  176. package/docs/enums/FamilyPosition.html +0 -239
  177. package/docs/enums/LoopType.html +0 -212
  178. package/docs/enums/RBColor.html +0 -204
  179. package/docs/enums/TopologicalProperty.html +0 -211
  180. package/docs/functions/arrayRemove.html +0 -208
  181. package/docs/functions/isThunk.html +0 -186
  182. package/docs/functions/toThunk.html +0 -186
  183. package/docs/functions/trampoline.html +0 -186
  184. package/docs/functions/trampolineAsync.html +0 -186
  185. package/docs/functions/uuidV4.html +0 -181
  186. package/docs/interfaces/IAVLTree.html +0 -1245
  187. package/docs/interfaces/IAbstractBinaryTree.html +0 -1101
  188. package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -335
  189. package/docs/interfaces/IAbstractGraph.html +0 -433
  190. package/docs/interfaces/IBST.html +0 -1245
  191. package/docs/interfaces/IDirectedGraph.html +0 -570
  192. package/docs/interfaces/IRBTree.html +0 -1247
  193. package/docs/interfaces/IUNDirectedGraph.html +0 -463
  194. package/docs/types/AVLTreeNodeNested.html +0 -182
  195. package/docs/types/AVLTreeOptions.html +0 -180
  196. package/docs/types/AbstractBinaryTreeNodeNested.html +0 -182
  197. package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -182
  198. package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -182
  199. package/docs/types/AbstractBinaryTreeOptions.html +0 -182
  200. package/docs/types/BSTComparator.html +0 -192
  201. package/docs/types/BSTNodeNested.html +0 -182
  202. package/docs/types/BSTOptions.html +0 -182
  203. package/docs/types/BinaryTreeDeletedResult.html +0 -189
  204. package/docs/types/BinaryTreeNodeId.html +0 -177
  205. package/docs/types/BinaryTreeNodeNested.html +0 -182
  206. package/docs/types/BinaryTreeNodePropertyName.html +0 -177
  207. package/docs/types/BinaryTreeOptions.html +0 -180
  208. package/docs/types/DFSOrderPattern.html +0 -177
  209. package/docs/types/DijkstraResult.html +0 -199
  210. package/docs/types/Direction.html +0 -177
  211. package/docs/types/DummyAny.html +0 -190
  212. package/docs/types/EdgeId.html +0 -177
  213. package/docs/types/HeapOptions.html +0 -198
  214. package/docs/types/IAVLTreeNode.html +0 -184
  215. package/docs/types/IBSTNode.html +0 -184
  216. package/docs/types/IBinaryTree.html +0 -182
  217. package/docs/types/IBinaryTreeNode.html +0 -184
  218. package/docs/types/IRBTreeNode.html +0 -184
  219. package/docs/types/ITreeMultiset.html +0 -182
  220. package/docs/types/ITreeMultisetNode.html +0 -184
  221. package/docs/types/KeyValueObject.html +0 -182
  222. package/docs/types/KeyValueObjectWithId.html +0 -184
  223. package/docs/types/MapGraphCoordinate.html +0 -177
  224. package/docs/types/NavigatorParams.html +0 -211
  225. package/docs/types/NodeOrPropertyName.html +0 -177
  226. package/docs/types/NonNumberNonObjectButDefined.html +0 -177
  227. package/docs/types/ObjectWithNonNumberId.html +0 -184
  228. package/docs/types/ObjectWithNumberId.html +0 -184
  229. package/docs/types/ObjectWithoutId.html +0 -177
  230. package/docs/types/PriorityQueueComparator.html +0 -197
  231. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -177
  232. package/docs/types/PriorityQueueOptions.html +0 -191
  233. package/docs/types/RBTreeNodeNested.html +0 -182
  234. package/docs/types/RBTreeOptions.html +0 -180
  235. package/docs/types/RestrictValById.html +0 -177
  236. package/docs/types/SegmentTreeNodeVal.html +0 -177
  237. package/docs/types/SpecifyOptional.html +0 -184
  238. package/docs/types/Thunk.html +0 -185
  239. package/docs/types/ToThunkFn.html +0 -185
  240. package/docs/types/TopologicalStatus.html +0 -177
  241. package/docs/types/TreeMultisetNodeNested.html +0 -182
  242. package/docs/types/TreeMultisetOptions.html +0 -180
  243. package/docs/types/TrlAsyncFn.html +0 -190
  244. package/docs/types/TrlFn.html +0 -190
  245. package/docs/types/Turning.html +0 -177
  246. package/docs/types/VertexId.html +0 -177
  247. package/docs/variables/THUNK_SYMBOL.html +0 -177
  248. package/rename_clear_files.sh +0 -29
  249. package/src/data-structures/binary-tree/aa-tree.ts +0 -1
  250. package/src/data-structures/binary-tree/abstract-binary-tree.ts +0 -1631
  251. package/src/data-structures/binary-tree/avl-tree.ts +0 -310
  252. package/src/data-structures/binary-tree/b-tree.ts +0 -1
  253. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -76
  254. package/src/data-structures/binary-tree/binary-tree.ts +0 -47
  255. package/src/data-structures/binary-tree/bst.ts +0 -537
  256. package/src/data-structures/binary-tree/index.ts +0 -12
  257. package/src/data-structures/binary-tree/rb-tree.ts +0 -101
  258. package/src/data-structures/binary-tree/segment-tree.ts +0 -242
  259. package/src/data-structures/binary-tree/splay-tree.ts +0 -1
  260. package/src/data-structures/binary-tree/tree-multiset.ts +0 -700
  261. package/src/data-structures/binary-tree/two-three-tree.ts +0 -1
  262. package/src/data-structures/diagrams/README.md +0 -5
  263. package/src/data-structures/graph/abstract-graph.ts +0 -1040
  264. package/src/data-structures/graph/directed-graph.ts +0 -470
  265. package/src/data-structures/graph/index.ts +0 -4
  266. package/src/data-structures/graph/map-graph.ts +0 -129
  267. package/src/data-structures/graph/undirected-graph.ts +0 -274
  268. package/src/data-structures/hash/coordinate-map.ts +0 -67
  269. package/src/data-structures/hash/coordinate-set.ts +0 -56
  270. package/src/data-structures/hash/hash-table.ts +0 -1
  271. package/src/data-structures/hash/index.ts +0 -6
  272. package/src/data-structures/hash/pair.ts +0 -1
  273. package/src/data-structures/hash/tree-map.ts +0 -1
  274. package/src/data-structures/hash/tree-set.ts +0 -1
  275. package/src/data-structures/heap/heap.ts +0 -212
  276. package/src/data-structures/heap/index.ts +0 -3
  277. package/src/data-structures/heap/max-heap.ts +0 -31
  278. package/src/data-structures/heap/min-heap.ts +0 -32
  279. package/src/data-structures/index.ts +0 -11
  280. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  281. package/src/data-structures/linked-list/index.ts +0 -3
  282. package/src/data-structures/linked-list/singly-linked-list.ts +0 -501
  283. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  284. package/src/data-structures/matrix/index.ts +0 -4
  285. package/src/data-structures/matrix/matrix.ts +0 -27
  286. package/src/data-structures/matrix/matrix2d.ts +0 -212
  287. package/src/data-structures/matrix/navigator.ts +0 -121
  288. package/src/data-structures/matrix/vector2d.ts +0 -316
  289. package/src/data-structures/priority-queue/index.ts +0 -3
  290. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -56
  291. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -57
  292. package/src/data-structures/priority-queue/priority-queue.ts +0 -359
  293. package/src/data-structures/queue/deque.ts +0 -297
  294. package/src/data-structures/queue/index.ts +0 -2
  295. package/src/data-structures/queue/queue.ts +0 -191
  296. package/src/data-structures/stack/index.ts +0 -1
  297. package/src/data-structures/stack/stack.ts +0 -98
  298. package/src/data-structures/tree/index.ts +0 -1
  299. package/src/data-structures/tree/tree.ts +0 -69
  300. package/src/data-structures/trie/index.ts +0 -1
  301. package/src/data-structures/trie/trie.ts +0 -225
  302. package/src/index.ts +0 -4
  303. package/src/interfaces/abstract-binary-tree.ts +0 -191
  304. package/src/interfaces/abstract-graph.ts +0 -31
  305. package/src/interfaces/avl-tree.ts +0 -25
  306. package/src/interfaces/binary-tree.ts +0 -6
  307. package/src/interfaces/bst.ts +0 -31
  308. package/src/interfaces/directed-graph.ts +0 -20
  309. package/src/interfaces/doubly-linked-list.ts +0 -1
  310. package/src/interfaces/heap.ts +0 -1
  311. package/src/interfaces/index.ts +0 -15
  312. package/src/interfaces/navigator.ts +0 -1
  313. package/src/interfaces/priority-queue.ts +0 -1
  314. package/src/interfaces/rb-tree.ts +0 -9
  315. package/src/interfaces/segment-tree.ts +0 -1
  316. package/src/interfaces/singly-linked-list.ts +0 -1
  317. package/src/interfaces/tree-multiset.ts +0 -7
  318. package/src/interfaces/undirected-graph.ts +0 -6
  319. package/src/types/data-structures/abstract-binary-tree.ts +0 -50
  320. package/src/types/data-structures/abstract-graph.ts +0 -11
  321. package/src/types/data-structures/avl-tree.ts +0 -5
  322. package/src/types/data-structures/binary-tree.ts +0 -5
  323. package/src/types/data-structures/bst.ts +0 -13
  324. package/src/types/data-structures/directed-graph.ts +0 -8
  325. package/src/types/data-structures/doubly-linked-list.ts +0 -1
  326. package/src/types/data-structures/heap.ts +0 -5
  327. package/src/types/data-structures/index.ts +0 -15
  328. package/src/types/data-structures/map-graph.ts +0 -1
  329. package/src/types/data-structures/navigator.ts +0 -13
  330. package/src/types/data-structures/priority-queue.ts +0 -9
  331. package/src/types/data-structures/rb-tree.ts +0 -8
  332. package/src/types/data-structures/segment-tree.ts +0 -1
  333. package/src/types/data-structures/singly-linked-list.ts +0 -1
  334. package/src/types/data-structures/tree-multiset.ts +0 -6
  335. package/src/types/helpers.ts +0 -1
  336. package/src/types/index.ts +0 -3
  337. package/src/types/utils/index.ts +0 -2
  338. package/src/types/utils/utils.ts +0 -6
  339. package/src/types/utils/validate-type.ts +0 -35
  340. package/src/utils/index.ts +0 -1
  341. package/src/utils/utils.ts +0 -79
  342. package/tsconfig.build.json +0 -33
@@ -1,310 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- import {BST, BSTNode} from './bst';
9
- import type {AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeletedResult, BinaryTreeNodeId} from '../../types';
10
- import {IAVLTree, IAVLTreeNode} from '../../interfaces';
11
-
12
- export class AVLTreeNode<T = any, NEIGHBOR extends AVLTreeNode<T, NEIGHBOR> = AVLTreeNodeNested<T>>
13
- extends BSTNode<T, NEIGHBOR>
14
- implements IAVLTreeNode<T, NEIGHBOR>
15
- {
16
- constructor(id: BinaryTreeNodeId, val?: T) {
17
- super(id, val);
18
- }
19
- }
20
-
21
- export class AVLTree<N extends AVLTreeNode<N['val'], N> = AVLTreeNode> extends BST<N> implements IAVLTree<N> {
22
- /**
23
- * This is a constructor function for an AVL tree data structure in TypeScript.
24
- * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
25
- * constructor of the AVLTree class. It allows you to customize the behavior of the AVL tree by providing different
26
- * options.
27
- */
28
- constructor(options?: AVLTreeOptions) {
29
- super(options);
30
- }
31
-
32
- /**
33
- * The function creates a new AVL tree node with the given id and value.
34
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is used to uniquely
35
- * identify each node in the tree.
36
- * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
37
- * that will be stored in the node.
38
- * @returns a new AVLTreeNode object with the specified id and value.
39
- */
40
- override createNode(id: BinaryTreeNodeId, val?: N['val']): N {
41
- return new AVLTreeNode<N['val'], N>(id, val) as N;
42
- }
43
-
44
- /**
45
- * The function overrides the add method of a binary tree node and balances the tree after inserting a new node.
46
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that we want to add.
47
- * @param [val] - The `val` parameter is an optional value that can be assigned to the node being added. It is of type
48
- * `N['val']`, which means it should be of the same type as the `val` property of the nodes in the binary tree.
49
- * @returns The method is returning the inserted node, or null or undefined if the insertion was not successful.
50
- */
51
- override add(id: BinaryTreeNodeId, val?: N['val']): N | null | undefined {
52
- // TODO support node as a param
53
- const inserted = super.add(id, val);
54
- if (inserted) this._balancePath(inserted);
55
- return inserted;
56
- }
57
-
58
- /**
59
- * The function overrides the remove method of the Binary Search Tree class, performs the removal operation, and
60
- * then balances the tree if necessary.
61
- * @param {BinaryTreeNodeId} id - The `id` parameter represents the identifier of the binary tree node that needs to be
62
- * removed from the AVL tree.
63
- * @param {boolean} [isUpdateAllLeftSum] - The `isUpdateAllLeftSum` parameter is an optional boolean parameter that
64
- * determines whether the left sum of all nodes in the AVL tree should be updated after removing a node. If
65
- * `isUpdateAllLeftSum` is set to `true`, the left sum of all nodes will be recalculated.
66
- * @returns The method is returning an array of `AVLTreeDeleted<N>` objects.
67
- */
68
- override remove(id: BinaryTreeNodeId, isUpdateAllLeftSum?: boolean): BinaryTreeDeletedResult<N>[] {
69
- const deletedResults = super.remove(id, isUpdateAllLeftSum);
70
- for (const {needBalanced} of deletedResults) {
71
- if (needBalanced) {
72
- this._balancePath(needBalanced);
73
- }
74
- }
75
- return deletedResults;
76
- }
77
-
78
- /**
79
- * The balance factor of a given AVL tree node is calculated by subtracting the height of its left subtree from the
80
- * height of its right subtree.
81
- * @param node - The parameter "node" is of type N, which represents a node in an AVL tree.
82
- * @returns The balance factor of the given AVL tree node.
83
- */
84
- protected _balanceFactor(node: N): number {
85
- if (!node.right)
86
- // node has no right subtree
87
- return -node.height;
88
- else if (!node.left)
89
- // node has no left subtree
90
- return +node.height;
91
- else return node.right.height - node.left.height;
92
- }
93
-
94
- /**
95
- * The function updates the height of a node in an AVL tree based on the heights of its left and right subtrees.
96
- * @param node - The parameter `node` is an AVLTreeNode object, which represents a node in an AVL tree.
97
- */
98
- protected _updateHeight(node: N): void {
99
- if (!node.left && !node.right) node.height = 0;
100
- else if (!node.left) {
101
- const rightHeight = node.right ? node.right.height : 0;
102
- node.height = 1 + rightHeight;
103
- } else if (!node.right) node.height = 1 + node.left.height;
104
- else node.height = 1 + Math.max(node.right.height, node.left.height);
105
- }
106
-
107
- /**
108
- * The `_balancePath` function balances the AVL tree by performing appropriate rotations based on the balance factor of
109
- * each node in the path from the given node to the root.
110
- * @param node - The `node` parameter is an AVLTreeNode object, which represents a node in an AVL tree.
111
- */
112
- protected _balancePath(node: N): void {
113
- const path = this.getPathToRoot(node, false); // first O(log n) + O(log n)
114
- for (let i = 0; i < path.length; i++) {
115
- // second O(log n)
116
- const A = path[i];
117
- // Update Heights: After inserting a node, backtrack from the insertion point to the root node, updating the height of each node along the way.
118
- this._updateHeight(A); // first O(1)
119
- // Check Balance: Simultaneously with height updates, check if each node violates the balance property of an AVL tree.
120
- // Balance Restoration: If a balance issue is discovered after inserting a node, it requires balance restoration operations. Balance restoration includes four basic cases where rotation operations need to be performed to fix the balance:
121
- switch (
122
- this._balanceFactor(A) // second O(1)
123
- ) {
124
- case -2:
125
- if (A && A.left) {
126
- if (this._balanceFactor(A.left) <= 0) {
127
- // second O(1)
128
- // Left Rotation (LL Rotation): When the inserted node is in the left subtree of the left subtree, causing an imbalance.
129
- this._balanceLL(A);
130
- } else {
131
- // Left-Right Rotation (LR Rotation): When the inserted node is in the right subtree of the left subtree, causing an imbalance.
132
- this._balanceLR(A);
133
- }
134
- }
135
- break;
136
- case +2:
137
- if (A && A.right) {
138
- if (this._balanceFactor(A.right) >= 0) {
139
- // Right Rotation (RR Rotation): When the inserted node is in the right subtree of the right subtree, causing an imbalance.
140
- this._balanceRR(A);
141
- } else {
142
- // Right-Left Rotation (RL Rotation): When the inserted node is in the left subtree of the right subtree, causing an imbalance.
143
- this._balanceRL(A);
144
- }
145
- }
146
- }
147
- // TODO So far, no sure if this is necessary that Recursive Repair: Once rotation operations are executed, it may cause imbalance issues at higher levels of the tree. Therefore, you need to recursively check and repair imbalance problems upwards until you reach the root node.
148
- }
149
- }
150
-
151
- /**
152
- * The `_balanceLL` function performs a left-left rotation on an AVL tree to balance it.
153
- * @param A - The parameter A is an AVLTreeNode object.
154
- */
155
- protected _balanceLL(A: N): void {
156
- const parentOfA = A.parent;
157
- const B = A.left;
158
- A.parent = B;
159
- if (B && B.right) {
160
- B.right.parent = A;
161
- }
162
- if (B) B.parent = parentOfA;
163
- if (A === this.root) {
164
- if (B) this._setRoot(B);
165
- } else {
166
- if (parentOfA?.left === A) {
167
- parentOfA.left = B;
168
- } else {
169
- if (parentOfA) parentOfA.right = B;
170
- }
171
- }
172
-
173
- if (B) {
174
- A.left = B.right;
175
- B.right = A;
176
- }
177
- this._updateHeight(A);
178
- if (B) this._updateHeight(B);
179
- }
180
-
181
- /**
182
- * The `_balanceLR` function performs a left-right rotation to balance an AVL tree.
183
- * @param A - A is an AVLTreeNode object.
184
- */
185
- protected _balanceLR(A: N): void {
186
- const parentOfA = A.parent;
187
- const B = A.left;
188
- let C = null;
189
- if (B) {
190
- C = B.right;
191
- }
192
- if (A) A.parent = C;
193
- if (B) B.parent = C;
194
-
195
- if (C) {
196
- if (C.left) {
197
- C.left.parent = B;
198
- }
199
- if (C.right) {
200
- C.right.parent = A;
201
- }
202
- C.parent = parentOfA;
203
- }
204
-
205
- if (A === this.root) {
206
- if (C) this._setRoot(C);
207
- } else {
208
- if (parentOfA) {
209
- if (parentOfA.left === A) {
210
- parentOfA.left = C;
211
- } else {
212
- parentOfA.right = C;
213
- }
214
- }
215
- }
216
-
217
- if (C) {
218
- A.left = C.right;
219
- if (B) B.right = C.left;
220
- C.left = B;
221
- C.right = A;
222
- }
223
-
224
- this._updateHeight(A);
225
- B && this._updateHeight(B);
226
- C && this._updateHeight(C);
227
- }
228
-
229
- /**
230
- * The `_balanceRR` function performs a right-right rotation on an AVL tree to balance it.
231
- * @param A - The parameter A is an AVLTreeNode object.
232
- */
233
- protected _balanceRR(A: N): void {
234
- const parentOfA = A.parent;
235
- const B = A.right;
236
- A.parent = B;
237
- if (B) {
238
- if (B.left) {
239
- B.left.parent = A;
240
- }
241
- B.parent = parentOfA;
242
- }
243
-
244
- if (A === this.root) {
245
- if (B) this._setRoot(B);
246
- } else {
247
- if (parentOfA) {
248
- if (parentOfA.left === A) {
249
- parentOfA.left = B;
250
- } else {
251
- parentOfA.right = B;
252
- }
253
- }
254
- }
255
-
256
- if (B) {
257
- A.right = B.left;
258
- B.left = A;
259
- }
260
- this._updateHeight(A);
261
- B && this._updateHeight(B);
262
- }
263
-
264
- /**
265
- * The `_balanceRL` function performs a right-left rotation to balance an AVL tree.
266
- * @param A - A is an AVLTreeNode object.
267
- */
268
- protected _balanceRL(A: N): void {
269
- const parentOfA = A.parent;
270
- const B = A.right;
271
- let C = null;
272
- if (B) {
273
- C = B.left;
274
- }
275
-
276
- A.parent = C;
277
- if (B) B.parent = C;
278
-
279
- if (C) {
280
- if (C.left) {
281
- C.left.parent = A;
282
- }
283
- if (C.right) {
284
- C.right.parent = B;
285
- }
286
- C.parent = parentOfA;
287
- }
288
-
289
- if (A === this.root) {
290
- if (C) this._setRoot(C);
291
- } else {
292
- if (parentOfA) {
293
- if (parentOfA.left === A) {
294
- parentOfA.left = C;
295
- } else {
296
- parentOfA.right = C;
297
- }
298
- }
299
- }
300
-
301
- if (C) A.right = C.left;
302
- if (B && C) B.left = C.right;
303
- if (C) C.left = A;
304
- if (C) C.right = B;
305
-
306
- this._updateHeight(A);
307
- B && this._updateHeight(B);
308
- C && this._updateHeight(C);
309
- }
310
- }
@@ -1 +0,0 @@
1
- export class BTree {}
@@ -1,76 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export class BinaryIndexedTree {
9
- /**
10
- * The constructor initializes an array with a specified length and fills it with zeros.
11
- * @param {number} n - The parameter `n` represents the size of the array that will be used to store the sum tree. The
12
- * sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array.
13
- * The size of the sum tree array is `n + 1` because
14
- */
15
- constructor(n: number) {
16
- this._sumTree = new Array<number>(n + 1).fill(0);
17
- }
18
-
19
- private _sumTree: number[];
20
-
21
- get sumTree(): number[] {
22
- return this._sumTree;
23
- }
24
-
25
- static lowBit(x: number) {
26
- return x & -x;
27
- }
28
-
29
- /**
30
- * The update function updates the values in a binary indexed tree by adding a delta value to the specified index and
31
- * its ancestors.
32
- * @param {number} i - The parameter `i` represents the index of the element in the `_sumTree` array that needs to be
33
- * updated.
34
- * @param {number} delta - The "delta" parameter represents the change in value that needs to be added to the element
35
- * at index "i" in the "_sumTree" array.
36
- */
37
- update(i: number, delta: number) {
38
- while (i < this._sumTree.length) {
39
- this._sumTree[i] += delta;
40
- i += BinaryIndexedTree.lowBit(i);
41
- }
42
- }
43
-
44
- /**
45
- * The function calculates the prefix sum of an array using a binary indexed tree.
46
- * @param {number} i - The parameter "i" in the function "getPrefixSum" represents the index of the element in the
47
- * array for which we want to calculate the prefix sum.
48
- * @returns The function `getPrefixSum` returns the prefix sum of the elements in the binary indexed tree up to index
49
- * `i`.
50
- */
51
- getPrefixSum(i: number) {
52
- let sum = 0;
53
- while (i > 0) {
54
- sum += this._sumTree[i];
55
- i -= BinaryIndexedTree.lowBit(i);
56
- }
57
- return sum;
58
- }
59
-
60
- /**
61
- * The function `getRangeSum` calculates the sum of a range of numbers in an array.
62
- * @param {number} start - The start parameter is the starting index of the range for which we want to calculate the
63
- * sum.
64
- * @param {number} end - The "end" parameter represents the ending index of the range for which we want to calculate
65
- * the sum.
66
- * @returns the sum of the elements in the range specified by the start and end indices.
67
- */
68
- getRangeSum(start: number, end: number): number {
69
- if (!(0 <= start && start <= end && end <= this._sumTree.length)) throw 'Index out of bounds';
70
- return this.getPrefixSum(end) - this.getPrefixSum(start);
71
- }
72
-
73
- protected _setSumTree(value: number[]) {
74
- this._sumTree = value;
75
- }
76
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
-
9
- import type {BinaryTreeNodeId, BinaryTreeNodeNested, BinaryTreeOptions} from '../../types';
10
- import {AbstractBinaryTree, AbstractBinaryTreeNode} from './abstract-binary-tree';
11
- import {IBinaryTree, IBinaryTreeNode} from '../../interfaces';
12
-
13
- export class BinaryTreeNode<T = any, NEIGHBOR extends BinaryTreeNode<T, NEIGHBOR> = BinaryTreeNodeNested<T>>
14
- extends AbstractBinaryTreeNode<T, NEIGHBOR>
15
- implements IBinaryTreeNode<T, NEIGHBOR>
16
- {
17
- constructor(id: BinaryTreeNodeId, val?: T) {
18
- super(id, val);
19
- }
20
- }
21
-
22
- export class BinaryTree<N extends BinaryTreeNode<N['val'], N> = BinaryTreeNode>
23
- extends AbstractBinaryTree<N>
24
- implements IBinaryTree<N>
25
- {
26
- /**
27
- * This is a constructor function for a binary tree class that takes an optional options parameter.
28
- * @param {BinaryTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
29
- * constructor of the `BinaryTree` class. It allows you to customize the behavior of the binary tree by providing
30
- * different configuration options.
31
- */
32
- constructor(options?: BinaryTreeOptions) {
33
- super(options);
34
- }
35
-
36
- /**
37
- * The function creates a new binary tree node with an optional value.
38
- * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier for the binary tree node. It is of type
39
- * `BinaryTreeNodeId`, which represents the unique identifier for each node in the binary tree.
40
- * @param [val] - The `val` parameter is an optional value that can be assigned to the node. It represents the value
41
- * stored in the node.
42
- * @returns a new instance of a BinaryTreeNode with the specified id and value.
43
- */
44
- createNode(id: BinaryTreeNodeId, val?: N['val']): N {
45
- return new BinaryTreeNode<N['val'], N>(id, val) as N;
46
- }
47
- }