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,297 +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 {DoublyLinkedList} from '../linked-list';
9
-
10
- // O(n) time complexity of obtaining the value
11
- // O(1) time complexity of adding at the beginning and the end
12
- export class Deque<T> extends DoublyLinkedList<T> {}
13
-
14
- // O(1) time complexity of obtaining the value
15
- // O(n) time complexity of adding at the beginning and the end
16
- // todo tested slowest one
17
- export class ObjectDeque<T = number> {
18
- constructor(capacity?: number) {
19
- if (capacity !== undefined) this._capacity = capacity;
20
- }
21
-
22
- private _nodes: {[key: number]: T} = {};
23
-
24
- get nodes(): {[p: number]: T} {
25
- return this._nodes;
26
- }
27
-
28
- private _capacity = Number.MAX_SAFE_INTEGER;
29
-
30
- get capacity(): number {
31
- return this._capacity;
32
- }
33
-
34
- set capacity(value: number) {
35
- this._capacity = value;
36
- }
37
-
38
- private _first = -1;
39
-
40
- get first(): number {
41
- return this._first;
42
- }
43
-
44
- set first(value: number) {
45
- this._first = value;
46
- }
47
-
48
- private _last = -1;
49
-
50
- get last(): number {
51
- return this._last;
52
- }
53
-
54
- set last(value: number) {
55
- this._last = value;
56
- }
57
-
58
- private _size = 0;
59
-
60
- get size(): number {
61
- return this._size;
62
- }
63
-
64
- /**
65
- * The "addFirst" function adds a value to the beginning of an array-like data structure.
66
- * @param {T} value - The `value` parameter represents the value that you want to add to the beginning of the data
67
- * structure.
68
- */
69
- addFirst(value: T) {
70
- if (this._size === 0) {
71
- const mid = Math.floor(this._capacity / 2);
72
- this._first = mid;
73
- this._last = mid;
74
- } else {
75
- this._first--;
76
- }
77
- this._nodes[this._first] = value;
78
- this._size++;
79
- }
80
-
81
- /**
82
- * The addLast function adds a value to the end of an array-like data structure.
83
- * @param {T} value - The `value` parameter represents the value that you want to add to the end of the data structure.
84
- */
85
- addLast(value: T) {
86
- if (this._size === 0) {
87
- const mid = Math.floor(this._capacity / 2);
88
- this._first = mid;
89
- this._last = mid;
90
- } else {
91
- this._last++;
92
- }
93
- this._nodes[this._last] = value;
94
- this._size++;
95
- }
96
-
97
- /**
98
- * The function `pollFirst()` removes and returns the first element in a data structure.
99
- * @returns The value of the first element in the data structure.
100
- */
101
- pollFirst() {
102
- if (!this._size) return;
103
- const value = this.peekFirst();
104
- delete this._nodes[this._first];
105
- this._first++;
106
- this._size--;
107
- return value;
108
- }
109
-
110
- /**
111
- * The `peekFirst` function returns the first element in an array-like data structure if it exists.
112
- * @returns The element at the first position of the `_nodes` array.
113
- */
114
- peekFirst() {
115
- if (this._size) return this._nodes[this._first];
116
- }
117
-
118
- /**
119
- * The `pollLast()` function removes and returns the last element in a data structure.
120
- * @returns The value that was removed from the data structure.
121
- */
122
- pollLast() {
123
- if (!this._size) return;
124
- const value = this.peekLast();
125
- delete this._nodes[this._last];
126
- this._last--;
127
- this._size--;
128
-
129
- return value;
130
- }
131
-
132
- /**
133
- * The `peekLast()` function returns the last element in an array-like data structure.
134
- * @returns The last element in the array "_nodes" is being returned.
135
- */
136
- peekLast() {
137
- if (this._size) return this._nodes[this._last];
138
- }
139
-
140
- /**
141
- * The get function returns the element at the specified index in an array-like data structure.
142
- * @param {number} index - The index parameter is a number that represents the position of the element you want to
143
- * retrieve from the array.
144
- * @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
145
- * index, `null` is returned.
146
- */
147
- get(index: number) {
148
- return this._nodes[this._first + index] || null;
149
- }
150
-
151
- /**
152
- * The function checks if the size of a data structure is less than or equal to zero.
153
- * @returns The method is returning a boolean value indicating whether the size of the object is less than or equal to 0.
154
- */
155
- isEmpty() {
156
- return this._size <= 0;
157
- }
158
-
159
- protected _seNodes(value: {[p: number]: T}) {
160
- this._nodes = value;
161
- }
162
-
163
- protected _setSize(value: number) {
164
- this._size = value;
165
- }
166
- }
167
-
168
- // O(1) time complexity of obtaining the value
169
- // O(n) time complexity of adding at the beginning and the end
170
- export class ArrayDeque<T> {
171
- protected _nodes: T[] = [];
172
-
173
- get size() {
174
- return this._nodes.length;
175
- }
176
-
177
- /**
178
- * O(n) time complexity of adding at the beginning and the end
179
- */
180
-
181
- /**
182
- * The function "addLast" adds a value to the end of an array.
183
- * @param {T} value - The value parameter represents the value that you want to add to the end of the array.
184
- * @returns The return value is the new length of the array after the value has been added.
185
- */
186
- addLast(value: T) {
187
- return this._nodes.push(value);
188
- }
189
-
190
- /**
191
- * The function "pollLast" returns and removes the last element from an array, or returns null if the array is empty.
192
- * @returns The method `pollLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
193
- */
194
- pollLast(): T | null {
195
- return this._nodes.pop() ?? null;
196
- }
197
-
198
- /**
199
- * The `pollFirst` function removes and returns the first element from an array, or returns null if the array is empty.
200
- * @returns The `pollFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
201
- * empty.
202
- */
203
- pollFirst(): T | null {
204
- return this._nodes.shift() ?? null;
205
- }
206
-
207
- /**
208
- * O(n) time complexity of adding at the beginning and the end
209
- */
210
-
211
- /**
212
- * The function "addFirst" adds a value to the beginning of an array.
213
- * @param {T} value - The value parameter represents the value that you want to add to the beginning of the array.
214
- * @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
215
- * `value` at the beginning.
216
- */
217
- addFirst(value: T) {
218
- return this._nodes.unshift(value);
219
- }
220
-
221
- /**
222
- * The `peekFirst` function returns the first element of an array or null if the array is empty.
223
- * @returns The function `peekFirst()` is returning the first element (`T`) of the `_nodes` array. If the array is
224
- * empty, it will return `null`.
225
- */
226
- peekFirst(): T | null {
227
- return this._nodes[0] ?? null;
228
- }
229
-
230
- /**
231
- * The `peekLast` function returns the last element of an array or null if the array is empty.
232
- * @returns The method `peekLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
233
- */
234
- peekLast(): T | null {
235
- return this._nodes[this._nodes.length - 1] ?? null;
236
- }
237
-
238
- /**
239
- * O(1) time complexity of obtaining the value
240
- */
241
-
242
- /**
243
- * The get function returns the element at the specified index in an array, or null if the index is out of bounds.
244
- * @param {number} index - The index parameter is a number that represents the position of the element you want to
245
- * retrieve from the array.
246
- * @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
247
- * will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
248
- */
249
- get(index: number): T | null {
250
- return this._nodes[index] ?? null;
251
- }
252
-
253
- /**
254
- * The set function assigns a value to a specific index in an array.
255
- * @param {number} index - The index parameter is a number that represents the position of the element in the array
256
- * that you want to set a new value for.
257
- * @param {T} value - The value parameter represents the new value that you want to set at the specified index in the
258
- * _nodes array.
259
- * @returns The value that is being set at the specified index in the `_nodes` array.
260
- */
261
- set(index: number, value: T) {
262
- return (this._nodes[index] = value);
263
- }
264
-
265
- /**
266
- * The insert function adds a value at a specified index in an array.
267
- * @param {number} index - The index parameter specifies the position at which the value should be inserted in the
268
- * array. It is a number that represents the index of the array where the value should be inserted. The index starts
269
- * from 0, so the first element of the array has an index of 0, the second element has
270
- * @param {T} value - The value parameter represents the value that you want to insert into the array at the specified
271
- * index.
272
- * @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
273
- * are being removed, an empty array will be returned.
274
- */
275
- insert(index: number, value: T) {
276
- return this._nodes.splice(index, 0, value);
277
- }
278
-
279
- /**
280
- * The remove function removes an element from an array at a specified index.
281
- * @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
282
- * is a number that represents the index of the element to be removed.
283
- * @returns The method is returning an array containing the removed element.
284
- */
285
- remove(index: number) {
286
- return this._nodes.splice(index, 1);
287
- }
288
-
289
- /**
290
- * The function checks if an array called "_nodes" is empty.
291
- * @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
292
- * is 0, indicating that the array is empty. Otherwise, it returns `false`.
293
- */
294
- isEmpty() {
295
- return this._nodes.length === 0;
296
- }
297
- }
@@ -1,2 +0,0 @@
1
- export * from './queue';
2
- export * from './deque';
@@ -1,191 +0,0 @@
1
- /**
2
- * @license MIT
3
- * @copyright Tyler Zeng <zrwusa@gmail.com>
4
- * @class
5
- */
6
- import {SinglyLinkedList} from '../linked-list';
7
-
8
- export class LinkedListQueue<T = any> extends SinglyLinkedList<T> {
9
- /**
10
- * The enqueue function adds a value to the end of an array.
11
- * @param {T} value - The value parameter represents the value that you want to add to the queue.
12
- */
13
- enqueue(value: T) {
14
- this.push(value);
15
- }
16
-
17
- /**
18
- * The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
19
- * @returns The method is returning the element at the front of the queue, or null if the queue is empty.
20
- */
21
- dequeue(): T | undefined {
22
- return this.shift();
23
- }
24
-
25
- /**
26
- * The `peek` function returns the value of the head node in a linked list, or `undefined` if the list is empty.
27
- * @returns The `peek()` method is returning the value of the `head` node if it exists, otherwise it returns `undefined`.
28
- */
29
- peek(): T | undefined {
30
- return this.head?.val;
31
- }
32
- }
33
-
34
- export class Queue<T = any> {
35
- /**
36
- * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
37
- * @param {T[]} [elements] - The `elements` parameter is an optional array of elements of type `T`. If provided, it
38
- * will be used to initialize the `_nodes` property of the class. If not provided, the `_nodes` property will be
39
- * initialized as an empty array.
40
- */
41
- constructor(elements?: T[]) {
42
- this._nodes = elements || [];
43
- this._offset = 0;
44
- }
45
-
46
- private _nodes: T[];
47
-
48
- get nodes(): T[] {
49
- return this._nodes;
50
- }
51
-
52
- set nodes(value: T[]) {
53
- this._nodes = value;
54
- }
55
-
56
- private _offset: number;
57
-
58
- get offset(): number {
59
- return this._offset;
60
- }
61
-
62
- set offset(value: number) {
63
- this._offset = value;
64
- }
65
-
66
- /**
67
- * The size function returns the number of elements in an array.
68
- * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
69
- */
70
- get size(): number {
71
- return this.nodes.length - this.offset;
72
- }
73
-
74
- /**
75
- * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
76
- * @public
77
- * @static
78
- * @param {T[]} elements - The "elements" parameter is an array of elements of type T.
79
- * @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
80
- * array.
81
- */
82
- static fromArray<T>(elements: T[]): Queue<T> {
83
- return new Queue(elements);
84
- }
85
-
86
- /**
87
- * The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
88
- * @param {T} element - The `element` parameter represents the element that you want to add to the queue.
89
- * @returns The `add` method is returning a `Queue<T>` object.
90
- */
91
- push(element: T): Queue<T> {
92
- this.nodes.push(element);
93
- return this;
94
- }
95
-
96
- /**
97
- * The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
98
- * necessary to optimize performance.
99
- * @returns The function `shift()` returns either the first element in the queue or `null` if the queue is empty.
100
- */
101
- shift(): T | undefined {
102
- if (this.size === 0) return undefined;
103
-
104
- const first = this.peek();
105
- this.offset += 1;
106
-
107
- if (this.offset * 2 < this.nodes.length) return first;
108
-
109
- // only remove dequeued elements when reaching half size
110
- // to decrease latency of shifting elements.
111
- this.nodes = this.nodes.slice(this.offset);
112
- this.offset = 0;
113
- return first;
114
- }
115
-
116
- /**
117
- * The `peek` function returns the first element of the array `_nodes` if it exists, otherwise it returns `null`.
118
- * @returns The `peek()` method returns the first element of the data structure, represented by the `_nodes` array at
119
- * the `_offset` index. If the data structure is empty (size is 0), it returns `null`.
120
- */
121
- peek(): T | undefined {
122
- return this.size > 0 ? this.nodes[this.offset] : undefined;
123
- }
124
-
125
- /**
126
- * The `peekLast` function returns the last element in an array-like data structure, or null if the structure is empty.
127
- * @returns The method `peekLast()` returns the last element of the `_nodes` array if the array is not empty. If the
128
- * array is empty, it returns `null`.
129
- */
130
- peekLast(): T | undefined {
131
- return this.size > 0 ? this.nodes[this.nodes.length - 1] : undefined;
132
- }
133
-
134
- /**
135
- * The enqueue function adds a value to the end of a queue.
136
- * @param {T} value - The value parameter represents the value that you want to add to the queue.
137
- */
138
- enqueue(value: T) {
139
- this.push(value);
140
- }
141
-
142
- /**
143
- * The `dequeue` function removes and returns the first element from a queue, or returns null if the queue is empty.
144
- * @returns The method is returning a value of type T or null.
145
- */
146
- dequeue(): T | undefined {
147
- return this.shift();
148
- }
149
-
150
- getAt(index: number): T | undefined {
151
- return this.nodes[index];
152
- }
153
-
154
- /**
155
- * The function checks if a data structure is empty by comparing its size to zero.
156
- * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
157
- */
158
- isEmpty(): boolean {
159
- return this.size === 0;
160
- }
161
-
162
- /**
163
- * The toArray() function returns an array of elements from the current offset to the end of the _nodes array.
164
- * @returns An array of type T is being returned.
165
- */
166
- toArray(): T[] {
167
- return this.nodes.slice(this.offset);
168
- }
169
-
170
- /**
171
- * The clear function resets the nodes array and offset to their initial values.
172
- */
173
- clear(): void {
174
- this.nodes = [];
175
- this.offset = 0;
176
- }
177
-
178
- /**
179
- * The `clone()` function returns a new Queue object with the same elements as the original Queue.
180
- * @returns The `clone()` method is returning a new instance of the `Queue` class.
181
- */
182
- clone(): Queue<T> {
183
- return new Queue(this.nodes.slice(this.offset));
184
- }
185
-
186
- *[Symbol.iterator]() {
187
- for (const item of this.nodes) {
188
- yield item;
189
- }
190
- }
191
- }
@@ -1 +0,0 @@
1
- export * from './stack';
@@ -1,98 +0,0 @@
1
- /**
2
- * @license MIT
3
- * @copyright Tyler Zeng <zrwusa@gmail.com>
4
- * @class
5
- */
6
- export class Stack<T = number> {
7
- protected _elements: T[];
8
-
9
- /**
10
- * The constructor initializes an array of elements, which can be provided as an optional parameter.
11
- * @param {T[]} [elements] - The `elements` parameter is an optional parameter of type `T[]`, which represents an array
12
- * of elements of type `T`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
13
- * is provided and is an array, it is assigned to the `_elements
14
- */
15
- constructor(elements?: T[]) {
16
- this._elements = Array.isArray(elements) ? elements : [];
17
- }
18
-
19
- /**
20
- * The function "fromArray" creates a new Stack object from an array of elements.
21
- * @param {T[]} elements - The `elements` parameter is an array of elements of type `T`.
22
- * @returns {Stack} The method is returning a new instance of the Stack class, initialized with the elements from the input
23
- * array.
24
- */
25
- static fromArray<T>(elements: T[]): Stack<T> {
26
- return new Stack(elements);
27
- }
28
-
29
- /**
30
- * The function checks if an array is empty and returns a boolean value.
31
- * @returns A boolean value indicating whether the `_elements` array is empty or not.
32
- */
33
- isEmpty(): boolean {
34
- return this._elements.length === 0;
35
- }
36
-
37
- /**
38
- * The size() function returns the number of elements in an array.
39
- * @returns The size of the elements array.
40
- */
41
- size(): number {
42
- return this._elements.length;
43
- }
44
-
45
- /**
46
- * The `peek` function returns the last element of an array, or null if the array is empty.
47
- * @returns The `peek()` function returns the last element of the `_elements` array, or `null` if the array is empty.
48
- */
49
- peek(): T | null {
50
- if (this.isEmpty()) return null;
51
-
52
- return this._elements[this._elements.length - 1];
53
- }
54
-
55
- /**
56
- * The push function adds an element to the stack and returns the updated stack.
57
- * @param {T} element - The parameter "element" is of type T, which means it can be any data type.
58
- * @returns The `push` method is returning the updated `Stack<T>` object.
59
- */
60
- push(element: T): Stack<T> {
61
- this._elements.push(element);
62
- return this;
63
- }
64
-
65
- /**
66
- * The `pop` function removes and returns the last element from an array, or returns null if the array is empty.
67
- * @returns The `pop()` method is returning the last element of the array `_elements` if the array is not empty. If the
68
- * array is empty, it returns `null`.
69
- */
70
- pop(): T | null {
71
- if (this.isEmpty()) return null;
72
-
73
- return this._elements.pop() || null;
74
- }
75
-
76
- /**
77
- * The toArray function returns a copy of the elements in an array.
78
- * @returns An array of type T.
79
- */
80
- toArray(): T[] {
81
- return this._elements.slice();
82
- }
83
-
84
- /**
85
- * The clear function clears the elements array.
86
- */
87
- clear(): void {
88
- this._elements = [];
89
- }
90
-
91
- /**
92
- * The `clone()` function returns a new `Stack` object with the same elements as the original stack.
93
- * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
94
- */
95
- clone(): Stack<T> {
96
- return new Stack(this._elements.slice());
97
- }
98
- }
@@ -1 +0,0 @@
1
- export * from './tree';
@@ -1,69 +0,0 @@
1
- export class TreeNode<T = any> {
2
- constructor(id: string, value?: T, children?: TreeNode<T>[]) {
3
- this._id = id;
4
- this._value = value || undefined;
5
- this._children = children || [];
6
- }
7
-
8
- private _id: string;
9
-
10
- get id(): string {
11
- return this._id;
12
- }
13
-
14
- set id(value: string) {
15
- this._id = value;
16
- }
17
-
18
- private _value?: T | undefined;
19
-
20
- get value(): T | undefined {
21
- return this._value;
22
- }
23
-
24
- set value(value: T | undefined) {
25
- this._value = value;
26
- }
27
-
28
- private _children?: TreeNode<T>[] | undefined;
29
-
30
- get children(): TreeNode<T>[] | undefined {
31
- return this._children;
32
- }
33
-
34
- set children(value: TreeNode<T>[] | undefined) {
35
- this._children = value;
36
- }
37
-
38
- addChildren(children: TreeNode<T> | TreeNode<T>[]) {
39
- if (!this.children) {
40
- this.children = [];
41
- }
42
- if (children instanceof TreeNode) {
43
- this.children.push(children);
44
- } else {
45
- this.children = this.children.concat(children);
46
- }
47
- }
48
-
49
- getHeight() {
50
- // eslint-disable-next-line @typescript-eslint/no-this-alias
51
- const beginRoot = this;
52
- let maxDepth = 1;
53
- if (beginRoot) {
54
- const bfs = (node: TreeNode<T>, level: number) => {
55
- if (level > maxDepth) {
56
- maxDepth = level;
57
- }
58
- const {children} = node;
59
- if (children) {
60
- for (let i = 0, len = children.length; i < len; i++) {
61
- bfs(children[i], level + 1);
62
- }
63
- }
64
- };
65
- bfs(beginRoot, 1);
66
- }
67
- return maxDepth;
68
- }
69
- }
@@ -1 +0,0 @@
1
- export * from './trie';