data-structure-typed 1.32.0 → 1.32.1

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 (348) hide show
  1. package/.github/workflows/ci.yml +12 -1
  2. package/.prettierrc.js +1 -1
  3. package/CHANGELOG.md +1 -1
  4. package/README.md +20 -3
  5. package/coverage/clover.xml +717 -717
  6. package/coverage/coverage-final.json +21 -21
  7. package/coverage/coverage-summary.json +68 -0
  8. package/coverage/lcov-report/index.html +1 -1
  9. package/coverage/lcov-report/src/data-structures/binary-tree/aa-tree.ts.html +1 -1
  10. package/coverage/lcov-report/src/data-structures/binary-tree/abstract-binary-tree.ts.html +19 -7
  11. package/coverage/lcov-report/src/data-structures/binary-tree/avl-tree.ts.html +5 -5
  12. package/coverage/lcov-report/src/data-structures/binary-tree/b-tree.ts.html +1 -1
  13. package/coverage/lcov-report/src/data-structures/binary-tree/binary-indexed-tree.ts.html +1 -1
  14. package/coverage/lcov-report/src/data-structures/binary-tree/binary-tree.ts.html +4 -4
  15. package/coverage/lcov-report/src/data-structures/binary-tree/bst.ts.html +7 -25
  16. package/coverage/lcov-report/src/data-structures/binary-tree/index.html +1 -1
  17. package/coverage/lcov-report/src/data-structures/binary-tree/index.ts.html +1 -1
  18. package/coverage/lcov-report/src/data-structures/binary-tree/rb-tree.ts.html +4 -4
  19. package/coverage/lcov-report/src/data-structures/binary-tree/segment-tree.ts.html +2 -2
  20. package/coverage/lcov-report/src/data-structures/binary-tree/splay-tree.ts.html +1 -1
  21. package/coverage/lcov-report/src/data-structures/binary-tree/tree-multiset.ts.html +9 -9
  22. package/coverage/lcov-report/src/data-structures/binary-tree/two-three-tree.ts.html +1 -1
  23. package/coverage/lcov-report/src/data-structures/graph/abstract-graph.ts.html +17 -17
  24. package/coverage/lcov-report/src/data-structures/graph/directed-graph.ts.html +5 -5
  25. package/coverage/lcov-report/src/data-structures/graph/index.html +1 -1
  26. package/coverage/lcov-report/src/data-structures/graph/index.ts.html +1 -1
  27. package/coverage/lcov-report/src/data-structures/graph/map-graph.ts.html +3 -3
  28. package/coverage/lcov-report/src/data-structures/graph/undirected-graph.ts.html +5 -5
  29. package/coverage/lcov-report/src/data-structures/hash/coordinate-map.ts.html +1 -1
  30. package/coverage/lcov-report/src/data-structures/hash/coordinate-set.ts.html +1 -1
  31. package/coverage/lcov-report/src/data-structures/hash/hash-table.ts.html +1 -1
  32. package/coverage/lcov-report/src/data-structures/hash/index.html +1 -1
  33. package/coverage/lcov-report/src/data-structures/hash/index.ts.html +1 -1
  34. package/coverage/lcov-report/src/data-structures/hash/pair.ts.html +1 -1
  35. package/coverage/lcov-report/src/data-structures/hash/tree-map.ts.html +1 -1
  36. package/coverage/lcov-report/src/data-structures/hash/tree-set.ts.html +1 -1
  37. package/coverage/lcov-report/src/data-structures/heap/heap.ts.html +4 -4
  38. package/coverage/lcov-report/src/data-structures/heap/index.html +1 -1
  39. package/coverage/lcov-report/src/data-structures/heap/index.ts.html +1 -1
  40. package/coverage/lcov-report/src/data-structures/heap/max-heap.ts.html +4 -4
  41. package/coverage/lcov-report/src/data-structures/heap/min-heap.ts.html +4 -4
  42. package/coverage/lcov-report/src/data-structures/index.html +1 -1
  43. package/coverage/lcov-report/src/data-structures/index.ts.html +1 -1
  44. package/coverage/lcov-report/src/data-structures/linked-list/doubly-linked-list.ts.html +1 -1
  45. package/coverage/lcov-report/src/data-structures/linked-list/index.html +1 -1
  46. package/coverage/lcov-report/src/data-structures/linked-list/index.ts.html +1 -1
  47. package/coverage/lcov-report/src/data-structures/linked-list/singly-linked-list.ts.html +1 -1
  48. package/coverage/lcov-report/src/data-structures/linked-list/skip-linked-list.ts.html +1 -1
  49. package/coverage/lcov-report/src/data-structures/matrix/index.html +1 -1
  50. package/coverage/lcov-report/src/data-structures/matrix/index.ts.html +1 -1
  51. package/coverage/lcov-report/src/data-structures/matrix/matrix.ts.html +3 -3
  52. package/coverage/lcov-report/src/data-structures/matrix/matrix2d.ts.html +1 -1
  53. package/coverage/lcov-report/src/data-structures/matrix/navigator.ts.html +4 -4
  54. package/coverage/lcov-report/src/data-structures/matrix/vector2d.ts.html +1 -1
  55. package/coverage/lcov-report/src/data-structures/priority-queue/index.html +1 -1
  56. package/coverage/lcov-report/src/data-structures/priority-queue/index.ts.html +1 -1
  57. package/coverage/lcov-report/src/data-structures/priority-queue/max-priority-queue.ts.html +6 -6
  58. package/coverage/lcov-report/src/data-structures/priority-queue/min-priority-queue.ts.html +3 -3
  59. package/coverage/lcov-report/src/data-structures/priority-queue/priority-queue.ts.html +32 -32
  60. package/coverage/lcov-report/src/data-structures/queue/deque.ts.html +5 -5
  61. package/coverage/lcov-report/src/data-structures/queue/index.html +1 -1
  62. package/coverage/lcov-report/src/data-structures/queue/index.ts.html +1 -1
  63. package/coverage/lcov-report/src/data-structures/queue/queue.ts.html +2 -2
  64. package/coverage/lcov-report/src/data-structures/stack/index.html +1 -1
  65. package/coverage/lcov-report/src/data-structures/stack/index.ts.html +1 -1
  66. package/coverage/lcov-report/src/data-structures/stack/stack.ts.html +1 -1
  67. package/coverage/lcov-report/src/data-structures/tree/index.html +1 -1
  68. package/coverage/lcov-report/src/data-structures/tree/index.ts.html +1 -1
  69. package/coverage/lcov-report/src/data-structures/tree/tree.ts.html +2 -2
  70. package/coverage/lcov-report/src/data-structures/trie/index.html +1 -1
  71. package/coverage/lcov-report/src/data-structures/trie/index.ts.html +1 -1
  72. package/coverage/lcov-report/src/data-structures/trie/trie.ts.html +1 -1
  73. package/coverage/lcov-report/src/index.html +1 -1
  74. package/coverage/lcov-report/src/index.ts.html +1 -1
  75. package/coverage/lcov-report/src/interfaces/index.html +1 -1
  76. package/coverage/lcov-report/src/interfaces/index.ts.html +1 -1
  77. package/coverage/lcov-report/src/types/data-structures/abstract-binary-tree.ts.html +1 -1
  78. package/coverage/lcov-report/src/types/data-structures/bst.ts.html +1 -1
  79. package/coverage/lcov-report/src/types/data-structures/directed-graph.ts.html +1 -1
  80. package/coverage/lcov-report/src/types/data-structures/index.html +1 -1
  81. package/coverage/lcov-report/src/types/data-structures/index.ts.html +1 -1
  82. package/coverage/lcov-report/src/types/data-structures/rb-tree.ts.html +1 -1
  83. package/coverage/lcov-report/src/types/index.html +1 -1
  84. package/coverage/lcov-report/src/types/index.ts.html +1 -1
  85. package/coverage/lcov-report/src/types/utils/index.html +1 -1
  86. package/coverage/lcov-report/src/types/utils/index.ts.html +1 -1
  87. package/coverage/lcov-report/src/utils/index.html +1 -1
  88. package/coverage/lcov-report/src/utils/index.ts.html +1 -1
  89. package/coverage/lcov-report/src/utils/utils.ts.html +4 -4
  90. package/coverage/lcov-report/test/utils/index.html +1 -1
  91. package/coverage/lcov-report/test/utils/index.ts.html +1 -1
  92. package/coverage/lcov-report/test/utils/magnitude.ts.html +1 -1
  93. package/coverage/lcov-report/test/utils/number.ts.html +1 -1
  94. package/coverage/lcov.info +1329 -1329
  95. package/dist/data-structures/binary-tree/abstract-binary-tree.js.map +1 -1
  96. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  97. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  98. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  99. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
  100. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  101. package/dist/data-structures/graph/abstract-graph.js.map +1 -1
  102. package/dist/data-structures/graph/directed-graph.js.map +1 -1
  103. package/dist/data-structures/graph/map-graph.js.map +1 -1
  104. package/dist/data-structures/graph/undirected-graph.js.map +1 -1
  105. package/dist/data-structures/heap/heap.js.map +1 -1
  106. package/dist/data-structures/heap/max-heap.js.map +1 -1
  107. package/dist/data-structures/heap/min-heap.js.map +1 -1
  108. package/dist/data-structures/matrix/matrix.js.map +1 -1
  109. package/dist/data-structures/matrix/navigator.js.map +1 -1
  110. package/dist/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  111. package/dist/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  112. package/dist/data-structures/priority-queue/priority-queue.js.map +1 -1
  113. package/dist/data-structures/queue/deque.js.map +1 -1
  114. package/dist/data-structures/queue/queue.js.map +1 -1
  115. package/dist/data-structures/tree/tree.js.map +1 -1
  116. package/dist/utils/utils.js.map +1 -1
  117. package/docs/classes/AVLTree.html +85 -85
  118. package/docs/classes/AVLTreeNode.html +15 -15
  119. package/docs/classes/AaTree.html +1 -1
  120. package/docs/classes/AbstractBinaryTree.html +78 -78
  121. package/docs/classes/AbstractBinaryTreeNode.html +21 -21
  122. package/docs/classes/AbstractEdge.html +11 -11
  123. package/docs/classes/AbstractGraph.html +36 -36
  124. package/docs/classes/AbstractVertex.html +8 -8
  125. package/docs/classes/ArrayDeque.html +14 -14
  126. package/docs/classes/BST.html +78 -78
  127. package/docs/classes/BSTNode.html +15 -15
  128. package/docs/classes/BTree.html +1 -1
  129. package/docs/classes/BinaryIndexedTree.html +9 -9
  130. package/docs/classes/BinaryTree.html +71 -71
  131. package/docs/classes/BinaryTreeNode.html +15 -15
  132. package/docs/classes/Character.html +4 -4
  133. package/docs/classes/CoordinateMap.html +9 -9
  134. package/docs/classes/CoordinateSet.html +8 -8
  135. package/docs/classes/Deque.html +34 -34
  136. package/docs/classes/DirectedEdge.html +15 -15
  137. package/docs/classes/DirectedGraph.html +52 -52
  138. package/docs/classes/DirectedVertex.html +6 -6
  139. package/docs/classes/DoublyLinkedList.html +37 -37
  140. package/docs/classes/DoublyLinkedListNode.html +11 -11
  141. package/docs/classes/HashTable.html +1 -1
  142. package/docs/classes/Heap.html +26 -26
  143. package/docs/classes/HeapItem.html +8 -8
  144. package/docs/classes/LinkedListQueue.html +35 -35
  145. package/docs/classes/MapEdge.html +13 -13
  146. package/docs/classes/MapGraph.html +56 -56
  147. package/docs/classes/MapVertex.html +12 -12
  148. package/docs/classes/Matrix2D.html +16 -16
  149. package/docs/classes/MatrixNTI2D.html +4 -4
  150. package/docs/classes/MaxHeap.html +26 -26
  151. package/docs/classes/MaxPriorityQueue.html +34 -34
  152. package/docs/classes/MinHeap.html +26 -26
  153. package/docs/classes/MinPriorityQueue.html +34 -34
  154. package/docs/classes/Navigator.html +10 -10
  155. package/docs/classes/ObjectDeque.html +25 -25
  156. package/docs/classes/Pair.html +1 -1
  157. package/docs/classes/PriorityQueue.html +32 -32
  158. package/docs/classes/Queue.html +22 -22
  159. package/docs/classes/RBTree.html +78 -78
  160. package/docs/classes/RBTreeNode.html +18 -18
  161. package/docs/classes/SegmentTree.html +17 -17
  162. package/docs/classes/SegmentTreeNode.html +20 -20
  163. package/docs/classes/SinglyLinkedList.html +35 -35
  164. package/docs/classes/SinglyLinkedListNode.html +8 -8
  165. package/docs/classes/SkipLinkedList.html +1 -1
  166. package/docs/classes/SplayTree.html +1 -1
  167. package/docs/classes/Stack.html +12 -12
  168. package/docs/classes/TreeMap.html +1 -1
  169. package/docs/classes/TreeMultiset.html +99 -99
  170. package/docs/classes/TreeMultisetNode.html +18 -18
  171. package/docs/classes/TreeNode.html +13 -13
  172. package/docs/classes/TreeSet.html +1 -1
  173. package/docs/classes/Trie.html +13 -13
  174. package/docs/classes/TrieNode.html +11 -11
  175. package/docs/classes/TwoThreeTree.html +1 -1
  176. package/docs/classes/UndirectedEdge.html +12 -12
  177. package/docs/classes/UndirectedGraph.html +40 -40
  178. package/docs/classes/UndirectedVertex.html +6 -6
  179. package/docs/classes/Vector2D.html +28 -28
  180. package/docs/enums/CP.html +4 -4
  181. package/docs/enums/FamilyPosition.html +8 -8
  182. package/docs/enums/LoopType.html +3 -3
  183. package/docs/enums/RBColor.html +3 -3
  184. package/docs/enums/TopologicalProperty.html +4 -4
  185. package/docs/functions/arrayRemove.html +1 -1
  186. package/docs/functions/isThunk.html +1 -1
  187. package/docs/functions/toThunk.html +1 -1
  188. package/docs/functions/trampoline.html +1 -1
  189. package/docs/functions/trampolineAsync.html +1 -1
  190. package/docs/functions/uuidV4.html +1 -1
  191. package/docs/index.html +11 -12
  192. package/docs/interfaces/IAVLTree.html +77 -77
  193. package/docs/interfaces/IAbstractBinaryTree.html +72 -72
  194. package/docs/interfaces/IAbstractBinaryTreeNode.html +14 -14
  195. package/docs/interfaces/IAbstractGraph.html +15 -15
  196. package/docs/interfaces/IBST.html +77 -77
  197. package/docs/interfaces/IDirectedGraph.html +23 -23
  198. package/docs/interfaces/IRBTree.html +77 -77
  199. package/docs/interfaces/IUNDirectedGraph.html +16 -16
  200. package/docs/types/AVLTreeNodeNested.html +1 -1
  201. package/docs/types/AVLTreeOptions.html +1 -1
  202. package/docs/types/AbstractBinaryTreeNodeNested.html +1 -1
  203. package/docs/types/AbstractBinaryTreeNodeProperties.html +1 -1
  204. package/docs/types/AbstractBinaryTreeNodeProperty.html +1 -1
  205. package/docs/types/AbstractBinaryTreeOptions.html +1 -1
  206. package/docs/types/BSTComparator.html +1 -1
  207. package/docs/types/BSTNodeNested.html +1 -1
  208. package/docs/types/BSTOptions.html +1 -1
  209. package/docs/types/BinaryTreeDeletedResult.html +1 -1
  210. package/docs/types/BinaryTreeNodeId.html +1 -1
  211. package/docs/types/BinaryTreeNodeNested.html +1 -1
  212. package/docs/types/BinaryTreeNodePropertyName.html +1 -1
  213. package/docs/types/BinaryTreeOptions.html +1 -1
  214. package/docs/types/DFSOrderPattern.html +1 -1
  215. package/docs/types/DijkstraResult.html +1 -1
  216. package/docs/types/Direction.html +1 -1
  217. package/docs/types/DummyAny.html +1 -1
  218. package/docs/types/EdgeId.html +1 -1
  219. package/docs/types/HeapOptions.html +1 -1
  220. package/docs/types/IAVLTreeNode.html +1 -1
  221. package/docs/types/IBSTNode.html +1 -1
  222. package/docs/types/IBinaryTree.html +1 -1
  223. package/docs/types/IBinaryTreeNode.html +1 -1
  224. package/docs/types/IRBTreeNode.html +1 -1
  225. package/docs/types/ITreeMultiset.html +1 -1
  226. package/docs/types/ITreeMultisetNode.html +1 -1
  227. package/docs/types/KeyValueObject.html +1 -1
  228. package/docs/types/KeyValueObjectWithId.html +1 -1
  229. package/docs/types/MapGraphCoordinate.html +1 -1
  230. package/docs/types/NavigatorParams.html +1 -1
  231. package/docs/types/NodeOrPropertyName.html +1 -1
  232. package/docs/types/NonNumberNonObjectButDefined.html +1 -1
  233. package/docs/types/ObjectWithNonNumberId.html +1 -1
  234. package/docs/types/ObjectWithNumberId.html +1 -1
  235. package/docs/types/ObjectWithoutId.html +1 -1
  236. package/docs/types/PriorityQueueComparator.html +1 -1
  237. package/docs/types/PriorityQueueDFSOrderPattern.html +1 -1
  238. package/docs/types/PriorityQueueOptions.html +1 -1
  239. package/docs/types/RBTreeNodeNested.html +1 -1
  240. package/docs/types/RBTreeOptions.html +1 -1
  241. package/docs/types/RestrictValById.html +1 -1
  242. package/docs/types/SegmentTreeNodeVal.html +1 -1
  243. package/docs/types/SpecifyOptional.html +1 -1
  244. package/docs/types/Thunk.html +1 -1
  245. package/docs/types/ToThunkFn.html +1 -1
  246. package/docs/types/TopologicalStatus.html +1 -1
  247. package/docs/types/TreeMultisetNodeNested.html +1 -1
  248. package/docs/types/TreeMultisetOptions.html +1 -1
  249. package/docs/types/TrlAsyncFn.html +1 -1
  250. package/docs/types/TrlFn.html +1 -1
  251. package/docs/types/Turning.html +1 -1
  252. package/docs/types/VertexId.html +1 -1
  253. package/docs/variables/THUNK_SYMBOL.html +1 -1
  254. package/jest.config.js +1 -0
  255. package/package.json +18 -6
  256. package/src/data-structures/binary-tree/aa-tree.ts +1 -0
  257. package/src/data-structures/binary-tree/abstract-binary-tree.ts +1631 -0
  258. package/src/data-structures/binary-tree/avl-tree.ts +310 -0
  259. package/src/data-structures/binary-tree/b-tree.ts +1 -0
  260. package/src/data-structures/binary-tree/binary-indexed-tree.ts +76 -0
  261. package/src/data-structures/binary-tree/binary-tree.ts +47 -0
  262. package/src/data-structures/binary-tree/bst.ts +537 -0
  263. package/src/data-structures/binary-tree/index.ts +12 -0
  264. package/src/data-structures/binary-tree/rb-tree.ts +101 -0
  265. package/src/data-structures/binary-tree/segment-tree.ts +242 -0
  266. package/src/data-structures/binary-tree/splay-tree.ts +1 -0
  267. package/src/data-structures/binary-tree/tree-multiset.ts +700 -0
  268. package/src/data-structures/binary-tree/two-three-tree.ts +1 -0
  269. package/src/data-structures/diagrams/README.md +5 -0
  270. package/src/data-structures/graph/abstract-graph.ts +1040 -0
  271. package/src/data-structures/graph/directed-graph.ts +470 -0
  272. package/src/data-structures/graph/index.ts +4 -0
  273. package/src/data-structures/graph/map-graph.ts +129 -0
  274. package/src/data-structures/graph/undirected-graph.ts +274 -0
  275. package/src/data-structures/hash/coordinate-map.ts +67 -0
  276. package/src/data-structures/hash/coordinate-set.ts +56 -0
  277. package/src/data-structures/hash/hash-table.ts +1 -0
  278. package/src/data-structures/hash/index.ts +6 -0
  279. package/src/data-structures/hash/pair.ts +1 -0
  280. package/src/data-structures/hash/tree-map.ts +1 -0
  281. package/src/data-structures/hash/tree-set.ts +1 -0
  282. package/src/data-structures/heap/heap.ts +212 -0
  283. package/src/data-structures/heap/index.ts +3 -0
  284. package/src/data-structures/heap/max-heap.ts +31 -0
  285. package/src/data-structures/heap/min-heap.ts +32 -0
  286. package/src/data-structures/index.ts +11 -0
  287. package/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
  288. package/src/data-structures/linked-list/index.ts +3 -0
  289. package/src/data-structures/linked-list/singly-linked-list.ts +501 -0
  290. package/src/data-structures/linked-list/skip-linked-list.ts +1 -0
  291. package/src/data-structures/matrix/index.ts +4 -0
  292. package/src/data-structures/matrix/matrix.ts +27 -0
  293. package/src/data-structures/matrix/matrix2d.ts +212 -0
  294. package/src/data-structures/matrix/navigator.ts +121 -0
  295. package/src/data-structures/matrix/vector2d.ts +316 -0
  296. package/src/data-structures/priority-queue/index.ts +3 -0
  297. package/src/data-structures/priority-queue/max-priority-queue.ts +56 -0
  298. package/src/data-structures/priority-queue/min-priority-queue.ts +57 -0
  299. package/src/data-structures/priority-queue/priority-queue.ts +359 -0
  300. package/src/data-structures/queue/deque.ts +297 -0
  301. package/src/data-structures/queue/index.ts +2 -0
  302. package/src/data-structures/queue/queue.ts +191 -0
  303. package/src/data-structures/stack/index.ts +1 -0
  304. package/src/data-structures/stack/stack.ts +98 -0
  305. package/src/data-structures/tree/index.ts +1 -0
  306. package/src/data-structures/tree/tree.ts +69 -0
  307. package/src/data-structures/trie/index.ts +1 -0
  308. package/src/data-structures/trie/trie.ts +225 -0
  309. package/src/index.ts +4 -0
  310. package/src/interfaces/abstract-binary-tree.ts +191 -0
  311. package/src/interfaces/abstract-graph.ts +31 -0
  312. package/src/interfaces/avl-tree.ts +25 -0
  313. package/src/interfaces/binary-tree.ts +6 -0
  314. package/src/interfaces/bst.ts +31 -0
  315. package/src/interfaces/directed-graph.ts +20 -0
  316. package/src/interfaces/doubly-linked-list.ts +1 -0
  317. package/src/interfaces/heap.ts +1 -0
  318. package/src/interfaces/index.ts +15 -0
  319. package/src/interfaces/navigator.ts +1 -0
  320. package/src/interfaces/priority-queue.ts +1 -0
  321. package/src/interfaces/rb-tree.ts +9 -0
  322. package/src/interfaces/segment-tree.ts +1 -0
  323. package/src/interfaces/singly-linked-list.ts +1 -0
  324. package/src/interfaces/tree-multiset.ts +7 -0
  325. package/src/interfaces/undirected-graph.ts +6 -0
  326. package/src/types/data-structures/abstract-binary-tree.ts +50 -0
  327. package/src/types/data-structures/abstract-graph.ts +11 -0
  328. package/src/types/data-structures/avl-tree.ts +5 -0
  329. package/src/types/data-structures/binary-tree.ts +5 -0
  330. package/src/types/data-structures/bst.ts +13 -0
  331. package/src/types/data-structures/directed-graph.ts +8 -0
  332. package/src/types/data-structures/doubly-linked-list.ts +1 -0
  333. package/src/types/data-structures/heap.ts +5 -0
  334. package/src/types/data-structures/index.ts +15 -0
  335. package/src/types/data-structures/map-graph.ts +1 -0
  336. package/src/types/data-structures/navigator.ts +13 -0
  337. package/src/types/data-structures/priority-queue.ts +9 -0
  338. package/src/types/data-structures/rb-tree.ts +8 -0
  339. package/src/types/data-structures/segment-tree.ts +1 -0
  340. package/src/types/data-structures/singly-linked-list.ts +1 -0
  341. package/src/types/data-structures/tree-multiset.ts +6 -0
  342. package/src/types/helpers.ts +1 -0
  343. package/src/types/index.ts +3 -0
  344. package/src/types/utils/index.ts +2 -0
  345. package/src/types/utils/utils.ts +6 -0
  346. package/src/types/utils/validate-type.ts +35 -0
  347. package/src/utils/index.ts +1 -0
  348. package/src/utils/utils.ts +79 -0
@@ -0,0 +1,56 @@
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 {PriorityQueue} from './priority-queue';
9
+ import type {PriorityQueueOptions, SpecifyOptional} from '../../types';
10
+
11
+ export class MaxPriorityQueue<T = number> extends PriorityQueue<T> {
12
+ constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>);
13
+ constructor(options: PriorityQueueOptions<T>);
14
+
15
+ /**
16
+ * The constructor initializes a priority queue with an optional comparator function.
17
+ * @param [options] - The `options` parameter is an optional object that can contain various properties to configure
18
+ * the priority queue.
19
+ */
20
+ constructor(options?: SpecifyOptional<PriorityQueueOptions<T>, 'comparator'>) {
21
+ super({
22
+ ...options,
23
+ comparator: options?.comparator
24
+ ? options.comparator
25
+ : (a: T, b: T) => {
26
+ const aKey = a as unknown as number,
27
+ bKey = b as unknown as number;
28
+ return bKey - aKey;
29
+ }
30
+ });
31
+ }
32
+
33
+ static override heapify<T extends number>(options?: Omit<PriorityQueueOptions<T>, 'comparator'>): MaxPriorityQueue<T>;
34
+ static override heapify<T>(options: PriorityQueueOptions<T>): MaxPriorityQueue<T>;
35
+
36
+ /**
37
+ * The function `heapify` creates a max priority queue from the given options and returns it.
38
+ * @param options - The `options` parameter is an object that contains configuration options for creating a priority
39
+ * queue. It can have the following properties:
40
+ * @returns a MaxPriorityQueue object.
41
+ */
42
+ static override heapify<T>(options: PriorityQueueOptions<T>): MaxPriorityQueue<T> {
43
+ const maxPQ = new MaxPriorityQueue<T>({
44
+ ...options,
45
+ comparator: options?.comparator
46
+ ? options.comparator
47
+ : (a: T, b: T) => {
48
+ const aKey = a as unknown as number,
49
+ bKey = b as unknown as number;
50
+ return bKey - aKey;
51
+ }
52
+ });
53
+ maxPQ._fix();
54
+ return maxPQ;
55
+ }
56
+ }
@@ -0,0 +1,57 @@
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 {PriorityQueue} from './priority-queue';
9
+ import type {PriorityQueueOptions, SpecifyOptional} from '../../types';
10
+
11
+ export class MinPriorityQueue<T = number> extends PriorityQueue<T> {
12
+ constructor(options?: Omit<PriorityQueueOptions<number>, 'comparator'>);
13
+ constructor(options: PriorityQueueOptions<T>);
14
+
15
+ /**
16
+ * The constructor initializes a priority queue with an optional comparator function.
17
+ * @param [options] - The `options` parameter is an optional object that can contain various configuration options for
18
+ * the `PriorityQueue` constructor.
19
+ */
20
+ constructor(options?: SpecifyOptional<PriorityQueueOptions<T>, 'comparator'>) {
21
+ super({
22
+ ...options,
23
+ comparator: options?.comparator
24
+ ? options.comparator
25
+ : (a: T, b: T) => {
26
+ const aKey = a as unknown as number,
27
+ bKey = b as unknown as number;
28
+ return aKey - bKey;
29
+ }
30
+ });
31
+ }
32
+
33
+ static override heapify<T extends number>(options?: Omit<PriorityQueueOptions<T>, 'comparator'>): MinPriorityQueue<T>;
34
+ static override heapify<T>(options: PriorityQueueOptions<T>): MinPriorityQueue<T>;
35
+
36
+ /**
37
+ * The function `heapify` creates a new MinPriorityQueue instance and sets the comparator function based on the options
38
+ * provided, and then fixes the heap structure of the queue.
39
+ * @param options - The `options` parameter is an object that contains configuration options for creating a priority
40
+ * queue. It can have the following properties:
41
+ * @returns a MinPriorityQueue object.
42
+ */
43
+ static override heapify<T>(options: PriorityQueueOptions<T>): MinPriorityQueue<T> {
44
+ const minPQ = new MinPriorityQueue<T>({
45
+ ...options,
46
+ comparator: options?.comparator
47
+ ? options.comparator
48
+ : (a: T, b: T) => {
49
+ const aKey = a as unknown as number,
50
+ bKey = b as unknown as number;
51
+ return aKey - bKey;
52
+ }
53
+ });
54
+ minPQ._fix();
55
+ return minPQ;
56
+ }
57
+ }
@@ -0,0 +1,359 @@
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 type {PriorityQueueComparator, PriorityQueueDFSOrderPattern, PriorityQueueOptions} from '../../types';
9
+
10
+ export class PriorityQueue<T = number> {
11
+ /**
12
+ * The constructor initializes a priority queue with the given options, including an array of nodes and a comparator
13
+ * function.
14
+ * @param options - The `options` parameter is an object that contains the following properties:
15
+ */
16
+ constructor(options: PriorityQueueOptions<T>) {
17
+ const {nodes, comparator, isFix = true} = options;
18
+ this._comparator = comparator;
19
+
20
+ if (nodes && Array.isArray(nodes) && nodes.length > 0) {
21
+ // TODO support distinct
22
+ this._nodes = [...nodes];
23
+ isFix && this._fix();
24
+ }
25
+ }
26
+
27
+ protected _nodes: T[] = [];
28
+
29
+ get nodes(): T[] {
30
+ return this._nodes;
31
+ }
32
+
33
+ get size(): number {
34
+ return this.nodes.length;
35
+ }
36
+
37
+ /**
38
+ * The `heapify` function creates a new PriorityQueue instance and fixes the heap property.
39
+ * @param options - The "options" parameter is an object that contains the configuration options for the PriorityQueue.
40
+ * It can include properties such as "comparator" which specifies the comparison function used to order the elements in
41
+ * the priority queue, and "initialValues" which is an array of initial values to be added to the priority
42
+ * @returns a new instance of the PriorityQueue class after performing the heapify operation on it.
43
+ */
44
+ static heapify<T>(options: PriorityQueueOptions<T>) {
45
+ const heap = new PriorityQueue(options);
46
+ heap._fix();
47
+ return heap;
48
+ }
49
+
50
+ /**
51
+ * The function checks if a priority queue is valid by creating a new priority queue with a fix option and then calling
52
+ * the isValid method.
53
+ * @param options - An object containing options for creating a priority queue. The options object should have the
54
+ * following properties:
55
+ * @returns the result of calling the `isValid()` method on a new instance of the `PriorityQueue` class.
56
+ */
57
+ static isPriorityQueueified<T>(options: Omit<PriorityQueueOptions<T>, 'isFix'>) {
58
+ return new PriorityQueue({...options, isFix: false}).isValid();
59
+ }
60
+
61
+ /**
62
+ * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
63
+ */
64
+ getNodes(): T[] {
65
+ return this._nodes;
66
+ }
67
+
68
+ /**
69
+ * The "add" function adds a node to the heap and ensures that the heap property is maintained.
70
+ * @param {T} node - The parameter "node" is of type T, which means it can be any data type. It represents the node
71
+ * that needs to be added to the heap.
72
+ */
73
+ add(node: T) {
74
+ this.nodes.push(node);
75
+ this._heapifyUp(this.size - 1);
76
+ }
77
+
78
+ /**
79
+ * The "has" function checks if a given node is present in the list of nodes.
80
+ * @param {T} node - The parameter `node` is of type `T`, which means it can be any type. It represents the node that
81
+ * we want to check if it exists in the `nodes` array.
82
+ * @returns a boolean value indicating whether the given node is included in the array of nodes.
83
+ */
84
+ has(node: T): boolean {
85
+ return this.nodes.includes(node);
86
+ }
87
+
88
+ /**
89
+ * The `peek` function returns the first element of the `nodes` array if it exists, otherwise it returns `null`.
90
+ * @returns The `peek()` function is returning the first element (`T`) of the `nodes` array if the `size` is not zero.
91
+ * Otherwise, it returns `null`.
92
+ */
93
+ peek(): T | null {
94
+ return this.size ? this.nodes[0] : null;
95
+ }
96
+
97
+ /**
98
+ * The `poll` function removes and returns the top element from a heap data structure.
99
+ * @returns The `poll()` method returns a value of type `T` or `null`.
100
+ */
101
+ poll(): T | null {
102
+ let res: T | null = null;
103
+ if (this.size > 1) {
104
+ this._swap(0, this.nodes.length - 1);
105
+ res = this.nodes.pop() ?? null;
106
+ this._heapifyDown(0);
107
+ } else if (this.size === 1) {
108
+ res = this.nodes.pop() ?? null;
109
+ }
110
+ return res;
111
+ }
112
+
113
+ /**
114
+ * The `leaf` function returns the last element in the `nodes` array or `null` if the array is empty.
115
+ * @returns The method `leaf()` is returning the last element (`T`) in the `nodes` array if it exists. If the array is
116
+ * empty or the last element is `null`, then it returns `null`.
117
+ */
118
+ leaf(): T | null {
119
+ return this.nodes[this.size - 1] ?? null;
120
+ }
121
+
122
+ /**
123
+ * The function checks if the size of an object is equal to zero and returns a boolean value indicating whether the
124
+ * object is empty or not.
125
+ * @returns The method `isEmpty()` is returning a boolean value indicating whether the size of the object is equal to
126
+ * 0.
127
+ */
128
+ isEmpty() {
129
+ return this.size === 0;
130
+ }
131
+
132
+ /**
133
+ * The clear function clears the nodes array.
134
+ */
135
+ clear() {
136
+ this._setNodes([]);
137
+ }
138
+
139
+ /**
140
+ * The toArray function returns an array containing all the elements in the nodes property.
141
+ * @returns An array of type T, which is the elements of the nodes property.
142
+ */
143
+ toArray(): T[] {
144
+ return [...this.nodes];
145
+ }
146
+
147
+ /**
148
+ * The `clone` function returns a new instance of the `PriorityQueue` class with the same nodes and comparator as the
149
+ * original instance.
150
+ * @returns The `clone()` method is returning a new instance of the `PriorityQueue` class with the same `nodes` and
151
+ * `comparator` properties as the original instance.
152
+ */
153
+ clone(): PriorityQueue<T> {
154
+ return new PriorityQueue<T>({
155
+ nodes: this.nodes,
156
+ comparator: this._comparator
157
+ });
158
+ }
159
+
160
+ // --- start additional methods ---
161
+ /**
162
+ * The `isValid` function recursively checks if a binary tree satisfies a certain condition.
163
+ * @returns The function `isValid()` returns a boolean value.
164
+ */
165
+ isValid(): boolean {
166
+ for (let i = 0; i < this.nodes.length; i++) {
167
+ const leftChildIndex = this._getLeft(i);
168
+ const rightChildIndex = this._getRight(i);
169
+ if (this._isValidIndex(leftChildIndex) && !this._compare(leftChildIndex, i)) {
170
+ return false;
171
+ }
172
+ if (this._isValidIndex(rightChildIndex) && !this._compare(rightChildIndex, i)) {
173
+ return false;
174
+ }
175
+ }
176
+ return true;
177
+ }
178
+
179
+ /**
180
+ * O(n log n), In scenarios with smaller data sizes, heap sort is generally expected to be slower than QuickSort or MergeSort.
181
+ */
182
+
183
+ /**
184
+ * The function sorts the elements in a data structure and returns them in an array.
185
+ * Plan to support sorting of duplicate elements.
186
+ * @returns The `sort()` method is returning an array of type `T[]`.
187
+ */
188
+ sort(): T[] {
189
+ const visitedNode: T[] = [];
190
+ while (this.size !== 0) {
191
+ const top = this.poll();
192
+ if (top) visitedNode.push(top);
193
+ }
194
+ return visitedNode;
195
+ }
196
+
197
+ /**
198
+ * The DFS function performs a depth-first search traversal on a binary tree and returns an array of visited nodes
199
+ * based on the specified traversal order.
200
+ * @param {PriorityQueueDFSOrderPattern} dfsMode - The dfsMode parameter is a string that specifies the order in which
201
+ * the nodes should be visited during the Depth-First Search (DFS) traversal. It can have one of the following values:
202
+ * @returns an array of type `(T | null)[]`.
203
+ */
204
+ DFS(dfsMode: PriorityQueueDFSOrderPattern): (T | null)[] {
205
+ const visitedNode: (T | null)[] = [];
206
+
207
+ const traverse = (cur: number) => {
208
+ const leftChildIndex = this._getLeft(cur);
209
+ const rightChildIndex = this._getRight(cur);
210
+ switch (dfsMode) {
211
+ case 'in':
212
+ this._isValidIndex(leftChildIndex) && traverse(leftChildIndex);
213
+ visitedNode.push(this.nodes[cur] ?? null);
214
+ this._isValidIndex(rightChildIndex) && traverse(rightChildIndex);
215
+ break;
216
+ case 'pre':
217
+ visitedNode.push(this.nodes[cur] ?? null);
218
+ this._isValidIndex(leftChildIndex) && traverse(leftChildIndex);
219
+ this._isValidIndex(rightChildIndex) && traverse(rightChildIndex);
220
+ break;
221
+ case 'post':
222
+ this._isValidIndex(leftChildIndex) && traverse(leftChildIndex);
223
+ this._isValidIndex(rightChildIndex) && traverse(rightChildIndex);
224
+ visitedNode.push(this.nodes[cur] ?? null);
225
+ break;
226
+ }
227
+ };
228
+
229
+ this._isValidIndex(0) && traverse(0);
230
+ return visitedNode;
231
+ }
232
+
233
+ protected _setNodes(value: T[]) {
234
+ this._nodes = value;
235
+ }
236
+
237
+ protected readonly _comparator: PriorityQueueComparator<T> = (a: T, b: T) => {
238
+ const aKey = a as unknown as number,
239
+ bKey = b as unknown as number;
240
+ return aKey - bKey;
241
+ };
242
+
243
+ /**
244
+ * The function compares two numbers using a custom comparator function.
245
+ * @param {number} a - The parameter "a" is a number that represents the index of a node in an array.
246
+ * @param {number} b - The parameter "b" is a number.
247
+ * @returns the result of the comparison between the elements at indices `a` and `b` in the `nodes` array. The
248
+ * comparison is done using the `_comparator` function, and if the result is greater than 0, `true` is returned,
249
+ * indicating that the element at index `a` is greater than the element at index `b`.
250
+ */
251
+ protected _compare(a: number, b: number) {
252
+ return this._comparator(this.nodes[a], this.nodes[b]) > 0;
253
+ }
254
+
255
+ /**
256
+ * The function swaps two elements in an array.
257
+ * @param {number} a - The parameter "a" is a number that represents the index of an element in an array.
258
+ * @param {number} b - The parameter "b" is a number.
259
+ */
260
+ protected _swap(a: number, b: number) {
261
+ const temp = this.nodes[a];
262
+ this.nodes[a] = this.nodes[b];
263
+ this.nodes[b] = temp;
264
+ }
265
+
266
+ /**
267
+ * The function checks if a given index is valid within an array.
268
+ * @param {number} index - The parameter "index" is of type number and represents the index value that needs to be
269
+ * checked for validity.
270
+ * @returns A boolean value indicating whether the given index is valid or not.
271
+ */
272
+ protected _isValidIndex(index: number): boolean {
273
+ return index > -1 && index < this.nodes.length;
274
+ }
275
+
276
+ /**
277
+ * The function returns the index of the parent node given the index of a child node in a binary tree.
278
+ * @param {number} child - The "child" parameter is a number representing the index of a child node in a binary tree.
279
+ * @returns the parent of the given child node.
280
+ */
281
+ protected _getParent(child: number): number {
282
+ return Math.floor((child - 1) / 2);
283
+ }
284
+
285
+ /**
286
+ * The function returns the index of the left child node in a binary tree given the index of its parent node.
287
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
288
+ * @returns the left child of a given parent node in a binary tree.
289
+ */
290
+ protected _getLeft(parent: number): number {
291
+ return 2 * parent + 1;
292
+ }
293
+
294
+ /**
295
+ * The function returns the index of the right child node in a binary tree given the index of its parent node.
296
+ * @param {number} parent - The parameter "parent" is a number that represents the index of a node in a binary tree.
297
+ * @returns the right child of a given parent node in a binary tree.
298
+ */
299
+ protected _getRight(parent: number): number {
300
+ return 2 * parent + 2;
301
+ }
302
+
303
+ /**
304
+ * The function returns the index of the smallest child node of a given parent node.
305
+ * @param {number} parent - The parent parameter is a number that represents the index of the parent node in a binary
306
+ * tree.
307
+ * @returns the minimum value between the parent node and its left and right child nodes.
308
+ */
309
+ protected _getComparedChild(parent: number) {
310
+ let min = parent;
311
+ const left = this._getLeft(parent),
312
+ right = this._getRight(parent);
313
+
314
+ if (left < this.size && this._compare(min, left)) {
315
+ min = left;
316
+ }
317
+ if (right < this.size && this._compare(min, right)) {
318
+ min = right;
319
+ }
320
+ return min;
321
+ }
322
+
323
+ /**
324
+ * The function `_heapifyUp` is used to maintain the heap property by moving an element up the heap until it is in the
325
+ * correct position.
326
+ * @param {number} start - The start parameter is the index of the element that needs to be moved up in the heap.
327
+ */
328
+ protected _heapifyUp(start: number) {
329
+ while (start > 0 && this._compare(this._getParent(start), start)) {
330
+ const parent = this._getParent(start);
331
+ this._swap(start, parent);
332
+ start = parent;
333
+ }
334
+ }
335
+
336
+ /**
337
+ * The function performs a heapify operation by comparing and swapping elements in a binary heap.
338
+ * @param {number} start - The start parameter is the index of the element in the heap from where the heapifyDown
339
+ * operation should start.
340
+ */
341
+ protected _heapifyDown(start: number) {
342
+ let min = this._getComparedChild(start);
343
+ while (this._compare(start, min)) {
344
+ this._swap(min, start);
345
+ start = min;
346
+ min = this._getComparedChild(start);
347
+ }
348
+ }
349
+
350
+ /**
351
+ * The _fix function performs a heapify operation on the elements of the heap starting from the middle and moving
352
+ * towards the root.
353
+ */
354
+ protected _fix() {
355
+ for (let i = Math.floor(this.size / 2); i > -1; i--) this._heapifyDown(i);
356
+ }
357
+
358
+ // --- end additional methods ---
359
+ }