data-structure-typed 2.0.5 → 2.1.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 (785) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/COMMANDS.md +27 -0
  3. package/README.md +5 -34
  4. package/benchmark/report.html +13 -77
  5. package/benchmark/report.json +152 -184
  6. package/dist/cjs/index.cjs +13062 -0
  7. package/dist/cjs/index.cjs.map +1 -0
  8. package/dist/esm/index.mjs +12984 -0
  9. package/dist/esm/index.mjs.map +1 -0
  10. package/dist/index.cjs +13091 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.js +13013 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/types/data-structures/base/iterable-element-base.d.ts +219 -0
  15. package/dist/types/data-structures/base/iterable-entry-base.d.ts +144 -0
  16. package/dist/types/data-structures/base/linear-base.d.ts +335 -0
  17. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -0
  18. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -0
  19. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -0
  20. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -0
  21. package/dist/types/data-structures/binary-tree/bst.d.ts +413 -0
  22. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -0
  23. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -0
  24. package/dist/{esm → types}/data-structures/binary-tree/tree-multi-map.d.ts +72 -69
  25. package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -0
  26. package/dist/types/data-structures/graph/directed-graph.d.ts +207 -0
  27. package/dist/types/data-structures/graph/map-graph.d.ts +78 -0
  28. package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -0
  29. package/dist/types/data-structures/hash/hash-map.d.ts +345 -0
  30. package/dist/types/data-structures/heap/heap.d.ts +503 -0
  31. package/dist/types/data-structures/heap/max-heap.d.ts +32 -0
  32. package/dist/types/data-structures/heap/min-heap.d.ts +33 -0
  33. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -0
  34. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -0
  35. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -0
  36. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -0
  37. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -0
  38. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -0
  39. package/dist/types/data-structures/queue/deque.d.ts +431 -0
  40. package/dist/types/data-structures/queue/queue.d.ts +308 -0
  41. package/dist/{cjs → types}/data-structures/stack/stack.d.ts +124 -102
  42. package/dist/types/data-structures/trie/trie.d.ts +350 -0
  43. package/dist/types/interfaces/binary-tree.d.ts +59 -0
  44. package/dist/types/interfaces/graph.d.ts +21 -0
  45. package/dist/{cjs → types}/types/data-structures/base/base.d.ts +1 -1
  46. package/dist/{esm → types}/types/data-structures/graph/abstract-graph.d.ts +4 -0
  47. package/dist/{cjs → types}/types/utils/utils.d.ts +1 -0
  48. package/dist/{esm → types}/utils/utils.d.ts +1 -1
  49. package/dist/umd/data-structure-typed.js +4693 -6484
  50. package/dist/umd/data-structure-typed.js.map +1 -0
  51. package/dist/umd/data-structure-typed.min.js +8 -6
  52. package/dist/umd/data-structure-typed.min.js.map +1 -1
  53. package/jest.integration.config.js +3 -0
  54. package/package.json +13 -12
  55. package/src/data-structures/base/iterable-element-base.ts +238 -115
  56. package/src/data-structures/base/iterable-entry-base.ts +96 -120
  57. package/src/data-structures/base/linear-base.ts +271 -277
  58. package/src/data-structures/binary-tree/avl-tree-counter.ts +196 -217
  59. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +188 -102
  60. package/src/data-structures/binary-tree/avl-tree.ts +237 -206
  61. package/src/data-structures/binary-tree/binary-tree.ts +665 -896
  62. package/src/data-structures/binary-tree/bst.ts +565 -572
  63. package/src/data-structures/binary-tree/red-black-tree.ts +157 -223
  64. package/src/data-structures/binary-tree/tree-counter.ts +195 -219
  65. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -98
  66. package/src/data-structures/graph/abstract-graph.ts +339 -264
  67. package/src/data-structures/graph/directed-graph.ts +146 -236
  68. package/src/data-structures/graph/map-graph.ts +63 -60
  69. package/src/data-structures/graph/undirected-graph.ts +129 -152
  70. package/src/data-structures/hash/hash-map.ts +274 -496
  71. package/src/data-structures/heap/heap.ts +389 -402
  72. package/src/data-structures/heap/max-heap.ts +12 -76
  73. package/src/data-structures/heap/min-heap.ts +13 -76
  74. package/src/data-structures/linked-list/doubly-linked-list.ts +426 -530
  75. package/src/data-structures/linked-list/singly-linked-list.ts +495 -517
  76. package/src/data-structures/linked-list/skip-linked-list.ts +1 -108
  77. package/src/data-structures/priority-queue/max-priority-queue.ts +12 -87
  78. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -88
  79. package/src/data-structures/priority-queue/priority-queue.ts +3 -92
  80. package/src/data-structures/queue/deque.ts +381 -357
  81. package/src/data-structures/queue/queue.ts +310 -264
  82. package/src/data-structures/stack/stack.ts +217 -131
  83. package/src/data-structures/trie/trie.ts +240 -175
  84. package/src/interfaces/binary-tree.ts +240 -6
  85. package/src/interfaces/graph.ts +37 -0
  86. package/src/types/data-structures/base/base.ts +5 -5
  87. package/src/types/data-structures/graph/abstract-graph.ts +5 -0
  88. package/src/types/utils/utils.ts +2 -0
  89. package/src/utils/utils.ts +9 -14
  90. package/test/integration/all-in-one.test.ts +1 -1
  91. package/test/integration/index.html +1 -1
  92. package/test/performance/benchmark-runner.ts +528 -0
  93. package/test/performance/data-structures/comparison/comparison.test.ts +27 -57
  94. package/test/performance/reportor.mjs +43 -43
  95. package/test/performance/runner-config.json +39 -0
  96. package/test/performance/single-suite-runner.ts +69 -0
  97. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +3 -3
  98. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +5 -5
  99. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  100. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +350 -90
  101. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -9
  102. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +2 -2
  103. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +25 -24
  104. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +112 -4
  105. package/test/unit/data-structures/graph/abstract-graph.test.ts +0 -4
  106. package/test/unit/data-structures/graph/directed-graph.test.ts +1 -1
  107. package/test/unit/data-structures/heap/heap.test.ts +14 -21
  108. package/test/unit/data-structures/heap/max-heap.test.ts +5 -9
  109. package/test/unit/data-structures/heap/min-heap.test.ts +1 -4
  110. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +14 -14
  111. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +0 -7
  112. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +8 -11
  113. package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +1 -4
  114. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +1 -4
  115. package/test/unit/data-structures/queue/queue.test.ts +4 -5
  116. package/test/unit/utils/utils.test.ts +0 -1
  117. package/tsconfig-base.json +20 -20
  118. package/tsconfig-types.json +17 -0
  119. package/tsconfig.test.json +8 -0
  120. package/tsup.config.js +11 -22
  121. package/tsup.node.config.ts +37 -0
  122. package/dist/cjs/common/index.js +0 -29
  123. package/dist/cjs/common/index.js.map +0 -1
  124. package/dist/cjs/data-structures/base/index.js +0 -19
  125. package/dist/cjs/data-structures/base/index.js.map +0 -1
  126. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +0 -116
  127. package/dist/cjs/data-structures/base/iterable-element-base.js +0 -202
  128. package/dist/cjs/data-structures/base/iterable-element-base.js.map +0 -1
  129. package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +0 -168
  130. package/dist/cjs/data-structures/base/iterable-entry-base.js +0 -241
  131. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +0 -1
  132. package/dist/cjs/data-structures/base/linear-base.d.ts +0 -277
  133. package/dist/cjs/data-structures/base/linear-base.js +0 -553
  134. package/dist/cjs/data-structures/base/linear-base.js.map +0 -1
  135. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +0 -214
  136. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +0 -409
  137. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  138. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -104
  139. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +0 -203
  140. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  141. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -302
  142. package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -599
  143. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +0 -1
  144. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +0 -295
  145. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  146. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +0 -910
  147. package/dist/cjs/data-structures/binary-tree/binary-tree.js +0 -2197
  148. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +0 -1
  149. package/dist/cjs/data-structures/binary-tree/bst.d.ts +0 -461
  150. package/dist/cjs/data-structures/binary-tree/bst.js +0 -880
  151. package/dist/cjs/data-structures/binary-tree/bst.js.map +0 -1
  152. package/dist/cjs/data-structures/binary-tree/index.js +0 -27
  153. package/dist/cjs/data-structures/binary-tree/index.js.map +0 -1
  154. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +0 -280
  155. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +0 -642
  156. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +0 -1
  157. package/dist/cjs/data-structures/binary-tree/segment-tree.js +0 -298
  158. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +0 -1
  159. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +0 -212
  160. package/dist/cjs/data-structures/binary-tree/tree-counter.js +0 -445
  161. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +0 -1
  162. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -267
  163. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +0 -365
  164. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  165. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -335
  166. package/dist/cjs/data-structures/graph/abstract-graph.js +0 -867
  167. package/dist/cjs/data-structures/graph/abstract-graph.js.map +0 -1
  168. package/dist/cjs/data-structures/graph/directed-graph.d.ts +0 -323
  169. package/dist/cjs/data-structures/graph/directed-graph.js +0 -613
  170. package/dist/cjs/data-structures/graph/directed-graph.js.map +0 -1
  171. package/dist/cjs/data-structures/graph/index.js +0 -21
  172. package/dist/cjs/data-structures/graph/index.js.map +0 -1
  173. package/dist/cjs/data-structures/graph/map-graph.d.ts +0 -84
  174. package/dist/cjs/data-structures/graph/map-graph.js +0 -111
  175. package/dist/cjs/data-structures/graph/map-graph.js.map +0 -1
  176. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +0 -231
  177. package/dist/cjs/data-structures/graph/undirected-graph.js +0 -445
  178. package/dist/cjs/data-structures/graph/undirected-graph.js.map +0 -1
  179. package/dist/cjs/data-structures/hash/hash-map.d.ts +0 -519
  180. package/dist/cjs/data-structures/hash/hash-map.js +0 -880
  181. package/dist/cjs/data-structures/hash/hash-map.js.map +0 -1
  182. package/dist/cjs/data-structures/hash/index.js +0 -18
  183. package/dist/cjs/data-structures/hash/index.js.map +0 -1
  184. package/dist/cjs/data-structures/heap/heap.d.ts +0 -578
  185. package/dist/cjs/data-structures/heap/heap.js +0 -911
  186. package/dist/cjs/data-structures/heap/heap.js.map +0 -1
  187. package/dist/cjs/data-structures/heap/index.js +0 -20
  188. package/dist/cjs/data-structures/heap/index.js.map +0 -1
  189. package/dist/cjs/data-structures/heap/max-heap.d.ts +0 -68
  190. package/dist/cjs/data-structures/heap/max-heap.js +0 -96
  191. package/dist/cjs/data-structures/heap/max-heap.js.map +0 -1
  192. package/dist/cjs/data-structures/heap/min-heap.d.ts +0 -68
  193. package/dist/cjs/data-structures/heap/min-heap.js +0 -87
  194. package/dist/cjs/data-structures/heap/min-heap.js.map +0 -1
  195. package/dist/cjs/data-structures/index.js +0 -29
  196. package/dist/cjs/data-structures/index.js.map +0 -1
  197. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +0 -885
  198. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +0 -1238
  199. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  200. package/dist/cjs/data-structures/linked-list/index.js +0 -20
  201. package/dist/cjs/data-structures/linked-list/index.js.map +0 -1
  202. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +0 -500
  203. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +0 -870
  204. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +0 -1
  205. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +0 -134
  206. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +0 -245
  207. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +0 -1
  208. package/dist/cjs/data-structures/matrix/index.js +0 -19
  209. package/dist/cjs/data-structures/matrix/index.js.map +0 -1
  210. package/dist/cjs/data-structures/matrix/matrix.js +0 -449
  211. package/dist/cjs/data-structures/matrix/matrix.js.map +0 -1
  212. package/dist/cjs/data-structures/matrix/navigator.js +0 -112
  213. package/dist/cjs/data-structures/matrix/navigator.js.map +0 -1
  214. package/dist/cjs/data-structures/priority-queue/index.js +0 -20
  215. package/dist/cjs/data-structures/priority-queue/index.js.map +0 -1
  216. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +0 -71
  217. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +0 -102
  218. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  219. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +0 -72
  220. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +0 -94
  221. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  222. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +0 -74
  223. package/dist/cjs/data-structures/priority-queue/priority-queue.js +0 -96
  224. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +0 -1
  225. package/dist/cjs/data-structures/queue/deque.d.ts +0 -458
  226. package/dist/cjs/data-structures/queue/deque.js +0 -919
  227. package/dist/cjs/data-structures/queue/deque.js.map +0 -1
  228. package/dist/cjs/data-structures/queue/index.js +0 -19
  229. package/dist/cjs/data-structures/queue/index.js.map +0 -1
  230. package/dist/cjs/data-structures/queue/queue.d.ts +0 -329
  231. package/dist/cjs/data-structures/queue/queue.js +0 -457
  232. package/dist/cjs/data-structures/queue/queue.js.map +0 -1
  233. package/dist/cjs/data-structures/stack/index.js +0 -18
  234. package/dist/cjs/data-structures/stack/index.js.map +0 -1
  235. package/dist/cjs/data-structures/stack/stack.js +0 -346
  236. package/dist/cjs/data-structures/stack/stack.js.map +0 -1
  237. package/dist/cjs/data-structures/tree/index.js +0 -18
  238. package/dist/cjs/data-structures/tree/index.js.map +0 -1
  239. package/dist/cjs/data-structures/tree/tree.js +0 -108
  240. package/dist/cjs/data-structures/tree/tree.js.map +0 -1
  241. package/dist/cjs/data-structures/trie/index.js +0 -18
  242. package/dist/cjs/data-structures/trie/index.js.map +0 -1
  243. package/dist/cjs/data-structures/trie/trie.d.ts +0 -351
  244. package/dist/cjs/data-structures/trie/trie.js +0 -594
  245. package/dist/cjs/data-structures/trie/trie.js.map +0 -1
  246. package/dist/cjs/index.js +0 -22
  247. package/dist/cjs/index.js.map +0 -1
  248. package/dist/cjs/interfaces/binary-tree.d.ts +0 -9
  249. package/dist/cjs/interfaces/binary-tree.js +0 -3
  250. package/dist/cjs/interfaces/binary-tree.js.map +0 -1
  251. package/dist/cjs/interfaces/doubly-linked-list.js +0 -3
  252. package/dist/cjs/interfaces/doubly-linked-list.js.map +0 -1
  253. package/dist/cjs/interfaces/graph.d.ts +0 -5
  254. package/dist/cjs/interfaces/graph.js +0 -3
  255. package/dist/cjs/interfaces/graph.js.map +0 -1
  256. package/dist/cjs/interfaces/heap.js +0 -3
  257. package/dist/cjs/interfaces/heap.js.map +0 -1
  258. package/dist/cjs/interfaces/index.js +0 -25
  259. package/dist/cjs/interfaces/index.js.map +0 -1
  260. package/dist/cjs/interfaces/navigator.js +0 -3
  261. package/dist/cjs/interfaces/navigator.js.map +0 -1
  262. package/dist/cjs/interfaces/priority-queue.js +0 -3
  263. package/dist/cjs/interfaces/priority-queue.js.map +0 -1
  264. package/dist/cjs/interfaces/segment-tree.js +0 -3
  265. package/dist/cjs/interfaces/segment-tree.js.map +0 -1
  266. package/dist/cjs/interfaces/singly-linked-list.js +0 -3
  267. package/dist/cjs/interfaces/singly-linked-list.js.map +0 -1
  268. package/dist/cjs/types/common.js +0 -3
  269. package/dist/cjs/types/common.js.map +0 -1
  270. package/dist/cjs/types/data-structures/base/base.js +0 -3
  271. package/dist/cjs/types/data-structures/base/base.js.map +0 -1
  272. package/dist/cjs/types/data-structures/base/index.js +0 -18
  273. package/dist/cjs/types/data-structures/base/index.js.map +0 -1
  274. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js +0 -3
  275. package/dist/cjs/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  276. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -3
  277. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  278. package/dist/cjs/types/data-structures/binary-tree/avl-tree.js +0 -3
  279. package/dist/cjs/types/data-structures/binary-tree/avl-tree.js.map +0 -1
  280. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js +0 -3
  281. package/dist/cjs/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  282. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -3
  283. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +0 -1
  284. package/dist/cjs/types/data-structures/binary-tree/bst.js +0 -3
  285. package/dist/cjs/types/data-structures/binary-tree/bst.js.map +0 -1
  286. package/dist/cjs/types/data-structures/binary-tree/index.js +0 -26
  287. package/dist/cjs/types/data-structures/binary-tree/index.js.map +0 -1
  288. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js +0 -3
  289. package/dist/cjs/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
  290. package/dist/cjs/types/data-structures/binary-tree/segment-tree.js +0 -3
  291. package/dist/cjs/types/data-structures/binary-tree/segment-tree.js.map +0 -1
  292. package/dist/cjs/types/data-structures/binary-tree/tree-counter.js +0 -3
  293. package/dist/cjs/types/data-structures/binary-tree/tree-counter.js.map +0 -1
  294. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js +0 -3
  295. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  296. package/dist/cjs/types/data-structures/graph/abstract-graph.d.ts +0 -10
  297. package/dist/cjs/types/data-structures/graph/abstract-graph.js +0 -3
  298. package/dist/cjs/types/data-structures/graph/abstract-graph.js.map +0 -1
  299. package/dist/cjs/types/data-structures/graph/directed-graph.js +0 -3
  300. package/dist/cjs/types/data-structures/graph/directed-graph.js.map +0 -1
  301. package/dist/cjs/types/data-structures/graph/index.js +0 -20
  302. package/dist/cjs/types/data-structures/graph/index.js.map +0 -1
  303. package/dist/cjs/types/data-structures/graph/map-graph.js +0 -3
  304. package/dist/cjs/types/data-structures/graph/map-graph.js.map +0 -1
  305. package/dist/cjs/types/data-structures/graph/undirected-graph.js +0 -3
  306. package/dist/cjs/types/data-structures/graph/undirected-graph.js.map +0 -1
  307. package/dist/cjs/types/data-structures/hash/hash-map.js +0 -3
  308. package/dist/cjs/types/data-structures/hash/hash-map.js.map +0 -1
  309. package/dist/cjs/types/data-structures/hash/index.js +0 -18
  310. package/dist/cjs/types/data-structures/hash/index.js.map +0 -1
  311. package/dist/cjs/types/data-structures/heap/heap.js +0 -3
  312. package/dist/cjs/types/data-structures/heap/heap.js.map +0 -1
  313. package/dist/cjs/types/data-structures/heap/index.js +0 -18
  314. package/dist/cjs/types/data-structures/heap/index.js.map +0 -1
  315. package/dist/cjs/types/data-structures/heap/max-heap.js +0 -3
  316. package/dist/cjs/types/data-structures/heap/max-heap.js.map +0 -1
  317. package/dist/cjs/types/data-structures/heap/min-heap.js +0 -3
  318. package/dist/cjs/types/data-structures/heap/min-heap.js.map +0 -1
  319. package/dist/cjs/types/data-structures/index.js +0 -29
  320. package/dist/cjs/types/data-structures/index.js.map +0 -1
  321. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js +0 -3
  322. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  323. package/dist/cjs/types/data-structures/linked-list/index.js +0 -20
  324. package/dist/cjs/types/data-structures/linked-list/index.js.map +0 -1
  325. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js +0 -3
  326. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
  327. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js +0 -3
  328. package/dist/cjs/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
  329. package/dist/cjs/types/data-structures/matrix/index.js +0 -19
  330. package/dist/cjs/types/data-structures/matrix/index.js.map +0 -1
  331. package/dist/cjs/types/data-structures/matrix/matrix.js +0 -3
  332. package/dist/cjs/types/data-structures/matrix/matrix.js.map +0 -1
  333. package/dist/cjs/types/data-structures/matrix/navigator.js +0 -3
  334. package/dist/cjs/types/data-structures/matrix/navigator.js.map +0 -1
  335. package/dist/cjs/types/data-structures/priority-queue/index.js +0 -20
  336. package/dist/cjs/types/data-structures/priority-queue/index.js.map +0 -1
  337. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js +0 -3
  338. package/dist/cjs/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  339. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js +0 -3
  340. package/dist/cjs/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  341. package/dist/cjs/types/data-structures/priority-queue/priority-queue.js +0 -3
  342. package/dist/cjs/types/data-structures/priority-queue/priority-queue.js.map +0 -1
  343. package/dist/cjs/types/data-structures/queue/deque.js +0 -3
  344. package/dist/cjs/types/data-structures/queue/deque.js.map +0 -1
  345. package/dist/cjs/types/data-structures/queue/index.js +0 -19
  346. package/dist/cjs/types/data-structures/queue/index.js.map +0 -1
  347. package/dist/cjs/types/data-structures/queue/queue.js +0 -3
  348. package/dist/cjs/types/data-structures/queue/queue.js.map +0 -1
  349. package/dist/cjs/types/data-structures/stack/index.js +0 -18
  350. package/dist/cjs/types/data-structures/stack/index.js.map +0 -1
  351. package/dist/cjs/types/data-structures/stack/stack.js +0 -3
  352. package/dist/cjs/types/data-structures/stack/stack.js.map +0 -1
  353. package/dist/cjs/types/data-structures/tree/index.js +0 -18
  354. package/dist/cjs/types/data-structures/tree/index.js.map +0 -1
  355. package/dist/cjs/types/data-structures/tree/tree.js +0 -3
  356. package/dist/cjs/types/data-structures/tree/tree.js.map +0 -1
  357. package/dist/cjs/types/data-structures/trie/index.js +0 -18
  358. package/dist/cjs/types/data-structures/trie/index.js.map +0 -1
  359. package/dist/cjs/types/data-structures/trie/trie.js +0 -3
  360. package/dist/cjs/types/data-structures/trie/trie.js.map +0 -1
  361. package/dist/cjs/types/index.js +0 -20
  362. package/dist/cjs/types/index.js.map +0 -1
  363. package/dist/cjs/types/utils/index.js +0 -19
  364. package/dist/cjs/types/utils/index.js.map +0 -1
  365. package/dist/cjs/types/utils/utils.js +0 -3
  366. package/dist/cjs/types/utils/utils.js.map +0 -1
  367. package/dist/cjs/types/utils/validate-type.js +0 -3
  368. package/dist/cjs/types/utils/validate-type.js.map +0 -1
  369. package/dist/cjs/utils/index.js +0 -19
  370. package/dist/cjs/utils/index.js.map +0 -1
  371. package/dist/cjs/utils/number.js +0 -24
  372. package/dist/cjs/utils/number.js.map +0 -1
  373. package/dist/cjs/utils/utils.d.ts +0 -209
  374. package/dist/cjs/utils/utils.js +0 -353
  375. package/dist/cjs/utils/utils.js.map +0 -1
  376. package/dist/esm/common/index.d.ts +0 -12
  377. package/dist/esm/common/index.js +0 -29
  378. package/dist/esm/common/index.js.map +0 -1
  379. package/dist/esm/data-structures/base/index.d.ts +0 -2
  380. package/dist/esm/data-structures/base/index.js +0 -3
  381. package/dist/esm/data-structures/base/index.js.map +0 -1
  382. package/dist/esm/data-structures/base/iterable-element-base.d.ts +0 -116
  383. package/dist/esm/data-structures/base/iterable-element-base.js +0 -199
  384. package/dist/esm/data-structures/base/iterable-element-base.js.map +0 -1
  385. package/dist/esm/data-structures/base/iterable-entry-base.d.ts +0 -168
  386. package/dist/esm/data-structures/base/iterable-entry-base.js +0 -237
  387. package/dist/esm/data-structures/base/iterable-entry-base.js.map +0 -1
  388. package/dist/esm/data-structures/base/linear-base.d.ts +0 -277
  389. package/dist/esm/data-structures/base/linear-base.js +0 -549
  390. package/dist/esm/data-structures/base/linear-base.js.map +0 -1
  391. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +0 -214
  392. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +0 -410
  393. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  394. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -104
  395. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +0 -205
  396. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  397. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +0 -302
  398. package/dist/esm/data-structures/binary-tree/avl-tree.js +0 -601
  399. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +0 -1
  400. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
  401. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js +0 -296
  402. package/dist/esm/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  403. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +0 -910
  404. package/dist/esm/data-structures/binary-tree/binary-tree.js +0 -2198
  405. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +0 -1
  406. package/dist/esm/data-structures/binary-tree/bst.d.ts +0 -461
  407. package/dist/esm/data-structures/binary-tree/bst.js +0 -881
  408. package/dist/esm/data-structures/binary-tree/bst.js.map +0 -1
  409. package/dist/esm/data-structures/binary-tree/index.d.ts +0 -10
  410. package/dist/esm/data-structures/binary-tree/index.js +0 -11
  411. package/dist/esm/data-structures/binary-tree/index.js.map +0 -1
  412. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +0 -280
  413. package/dist/esm/data-structures/binary-tree/red-black-tree.js +0 -641
  414. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +0 -1
  415. package/dist/esm/data-structures/binary-tree/segment-tree.d.ts +0 -160
  416. package/dist/esm/data-structures/binary-tree/segment-tree.js +0 -295
  417. package/dist/esm/data-structures/binary-tree/segment-tree.js.map +0 -1
  418. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +0 -212
  419. package/dist/esm/data-structures/binary-tree/tree-counter.js +0 -446
  420. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +0 -1
  421. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +0 -367
  422. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  423. package/dist/esm/data-structures/graph/abstract-graph.d.ts +0 -335
  424. package/dist/esm/data-structures/graph/abstract-graph.js +0 -862
  425. package/dist/esm/data-structures/graph/abstract-graph.js.map +0 -1
  426. package/dist/esm/data-structures/graph/directed-graph.d.ts +0 -323
  427. package/dist/esm/data-structures/graph/directed-graph.js +0 -609
  428. package/dist/esm/data-structures/graph/directed-graph.js.map +0 -1
  429. package/dist/esm/data-structures/graph/index.d.ts +0 -4
  430. package/dist/esm/data-structures/graph/index.js +0 -5
  431. package/dist/esm/data-structures/graph/index.js.map +0 -1
  432. package/dist/esm/data-structures/graph/map-graph.d.ts +0 -84
  433. package/dist/esm/data-structures/graph/map-graph.js +0 -108
  434. package/dist/esm/data-structures/graph/map-graph.js.map +0 -1
  435. package/dist/esm/data-structures/graph/undirected-graph.d.ts +0 -231
  436. package/dist/esm/data-structures/graph/undirected-graph.js +0 -439
  437. package/dist/esm/data-structures/graph/undirected-graph.js.map +0 -1
  438. package/dist/esm/data-structures/hash/hash-map.d.ts +0 -519
  439. package/dist/esm/data-structures/hash/hash-map.js +0 -878
  440. package/dist/esm/data-structures/hash/hash-map.js.map +0 -1
  441. package/dist/esm/data-structures/hash/index.d.ts +0 -1
  442. package/dist/esm/data-structures/hash/index.js +0 -2
  443. package/dist/esm/data-structures/hash/index.js.map +0 -1
  444. package/dist/esm/data-structures/heap/heap.d.ts +0 -578
  445. package/dist/esm/data-structures/heap/heap.js +0 -914
  446. package/dist/esm/data-structures/heap/heap.js.map +0 -1
  447. package/dist/esm/data-structures/heap/index.d.ts +0 -3
  448. package/dist/esm/data-structures/heap/index.js +0 -4
  449. package/dist/esm/data-structures/heap/index.js.map +0 -1
  450. package/dist/esm/data-structures/heap/max-heap.d.ts +0 -68
  451. package/dist/esm/data-structures/heap/max-heap.js +0 -95
  452. package/dist/esm/data-structures/heap/max-heap.js.map +0 -1
  453. package/dist/esm/data-structures/heap/min-heap.d.ts +0 -68
  454. package/dist/esm/data-structures/heap/min-heap.js +0 -83
  455. package/dist/esm/data-structures/heap/min-heap.js.map +0 -1
  456. package/dist/esm/data-structures/index.d.ts +0 -12
  457. package/dist/esm/data-structures/index.js +0 -13
  458. package/dist/esm/data-structures/index.js.map +0 -1
  459. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +0 -885
  460. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +0 -1236
  461. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  462. package/dist/esm/data-structures/linked-list/index.d.ts +0 -3
  463. package/dist/esm/data-structures/linked-list/index.js +0 -4
  464. package/dist/esm/data-structures/linked-list/index.js.map +0 -1
  465. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +0 -500
  466. package/dist/esm/data-structures/linked-list/singly-linked-list.js +0 -866
  467. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +0 -1
  468. package/dist/esm/data-structures/linked-list/skip-linked-list.d.ts +0 -134
  469. package/dist/esm/data-structures/linked-list/skip-linked-list.js +0 -243
  470. package/dist/esm/data-structures/linked-list/skip-linked-list.js.map +0 -1
  471. package/dist/esm/data-structures/matrix/index.d.ts +0 -2
  472. package/dist/esm/data-structures/matrix/index.js +0 -3
  473. package/dist/esm/data-structures/matrix/index.js.map +0 -1
  474. package/dist/esm/data-structures/matrix/matrix.d.ts +0 -168
  475. package/dist/esm/data-structures/matrix/matrix.js +0 -444
  476. package/dist/esm/data-structures/matrix/matrix.js.map +0 -1
  477. package/dist/esm/data-structures/matrix/navigator.d.ts +0 -55
  478. package/dist/esm/data-structures/matrix/navigator.js +0 -114
  479. package/dist/esm/data-structures/matrix/navigator.js.map +0 -1
  480. package/dist/esm/data-structures/priority-queue/index.d.ts +0 -3
  481. package/dist/esm/data-structures/priority-queue/index.js +0 -4
  482. package/dist/esm/data-structures/priority-queue/index.js.map +0 -1
  483. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +0 -71
  484. package/dist/esm/data-structures/priority-queue/max-priority-queue.js +0 -101
  485. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  486. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +0 -72
  487. package/dist/esm/data-structures/priority-queue/min-priority-queue.js +0 -90
  488. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  489. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +0 -74
  490. package/dist/esm/data-structures/priority-queue/priority-queue.js +0 -92
  491. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +0 -1
  492. package/dist/esm/data-structures/queue/deque.d.ts +0 -458
  493. package/dist/esm/data-structures/queue/deque.js +0 -915
  494. package/dist/esm/data-structures/queue/deque.js.map +0 -1
  495. package/dist/esm/data-structures/queue/index.d.ts +0 -2
  496. package/dist/esm/data-structures/queue/index.js +0 -3
  497. package/dist/esm/data-structures/queue/index.js.map +0 -1
  498. package/dist/esm/data-structures/queue/queue.d.ts +0 -329
  499. package/dist/esm/data-structures/queue/queue.js +0 -452
  500. package/dist/esm/data-structures/queue/queue.js.map +0 -1
  501. package/dist/esm/data-structures/stack/index.d.ts +0 -1
  502. package/dist/esm/data-structures/stack/index.js +0 -2
  503. package/dist/esm/data-structures/stack/index.js.map +0 -1
  504. package/dist/esm/data-structures/stack/stack.d.ts +0 -284
  505. package/dist/esm/data-structures/stack/stack.js +0 -342
  506. package/dist/esm/data-structures/stack/stack.js.map +0 -1
  507. package/dist/esm/data-structures/tree/index.d.ts +0 -1
  508. package/dist/esm/data-structures/tree/index.js +0 -2
  509. package/dist/esm/data-structures/tree/index.js.map +0 -1
  510. package/dist/esm/data-structures/tree/tree.d.ts +0 -62
  511. package/dist/esm/data-structures/tree/tree.js +0 -107
  512. package/dist/esm/data-structures/tree/tree.js.map +0 -1
  513. package/dist/esm/data-structures/trie/index.d.ts +0 -1
  514. package/dist/esm/data-structures/trie/index.js +0 -2
  515. package/dist/esm/data-structures/trie/index.js.map +0 -1
  516. package/dist/esm/data-structures/trie/trie.d.ts +0 -351
  517. package/dist/esm/data-structures/trie/trie.js +0 -592
  518. package/dist/esm/data-structures/trie/trie.js.map +0 -1
  519. package/dist/esm/index.d.ts +0 -5
  520. package/dist/esm/index.js +0 -6
  521. package/dist/esm/index.js.map +0 -1
  522. package/dist/esm/interfaces/binary-tree.d.ts +0 -9
  523. package/dist/esm/interfaces/binary-tree.js +0 -2
  524. package/dist/esm/interfaces/binary-tree.js.map +0 -1
  525. package/dist/esm/interfaces/doubly-linked-list.d.ts +0 -1
  526. package/dist/esm/interfaces/doubly-linked-list.js +0 -2
  527. package/dist/esm/interfaces/doubly-linked-list.js.map +0 -1
  528. package/dist/esm/interfaces/graph.d.ts +0 -5
  529. package/dist/esm/interfaces/graph.js +0 -2
  530. package/dist/esm/interfaces/graph.js.map +0 -1
  531. package/dist/esm/interfaces/heap.d.ts +0 -1
  532. package/dist/esm/interfaces/heap.js +0 -2
  533. package/dist/esm/interfaces/heap.js.map +0 -1
  534. package/dist/esm/interfaces/index.d.ts +0 -8
  535. package/dist/esm/interfaces/index.js +0 -9
  536. package/dist/esm/interfaces/index.js.map +0 -1
  537. package/dist/esm/interfaces/navigator.d.ts +0 -1
  538. package/dist/esm/interfaces/navigator.js +0 -2
  539. package/dist/esm/interfaces/navigator.js.map +0 -1
  540. package/dist/esm/interfaces/priority-queue.d.ts +0 -1
  541. package/dist/esm/interfaces/priority-queue.js +0 -2
  542. package/dist/esm/interfaces/priority-queue.js.map +0 -1
  543. package/dist/esm/interfaces/segment-tree.d.ts +0 -1
  544. package/dist/esm/interfaces/segment-tree.js +0 -2
  545. package/dist/esm/interfaces/segment-tree.js.map +0 -1
  546. package/dist/esm/interfaces/singly-linked-list.d.ts +0 -1
  547. package/dist/esm/interfaces/singly-linked-list.js +0 -2
  548. package/dist/esm/interfaces/singly-linked-list.js.map +0 -1
  549. package/dist/esm/types/common.d.ts +0 -15
  550. package/dist/esm/types/common.js +0 -2
  551. package/dist/esm/types/common.js.map +0 -1
  552. package/dist/esm/types/data-structures/base/base.d.ts +0 -13
  553. package/dist/esm/types/data-structures/base/base.js +0 -2
  554. package/dist/esm/types/data-structures/base/base.js.map +0 -1
  555. package/dist/esm/types/data-structures/base/index.d.ts +0 -1
  556. package/dist/esm/types/data-structures/base/index.js +0 -2
  557. package/dist/esm/types/data-structures/base/index.js.map +0 -1
  558. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -2
  559. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
  560. package/dist/esm/types/data-structures/binary-tree/avl-tree-counter.js.map +0 -1
  561. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -2
  562. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
  563. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.js.map +0 -1
  564. package/dist/esm/types/data-structures/binary-tree/avl-tree.d.ts +0 -2
  565. package/dist/esm/types/data-structures/binary-tree/avl-tree.js +0 -2
  566. package/dist/esm/types/data-structures/binary-tree/avl-tree.js.map +0 -1
  567. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -1
  568. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
  569. package/dist/esm/types/data-structures/binary-tree/binary-indexed-tree.js.map +0 -1
  570. package/dist/esm/types/data-structures/binary-tree/binary-tree.d.ts +0 -29
  571. package/dist/esm/types/data-structures/binary-tree/binary-tree.js +0 -2
  572. package/dist/esm/types/data-structures/binary-tree/binary-tree.js.map +0 -1
  573. package/dist/esm/types/data-structures/binary-tree/bst.d.ts +0 -12
  574. package/dist/esm/types/data-structures/binary-tree/bst.js +0 -2
  575. package/dist/esm/types/data-structures/binary-tree/bst.js.map +0 -1
  576. package/dist/esm/types/data-structures/binary-tree/index.d.ts +0 -9
  577. package/dist/esm/types/data-structures/binary-tree/index.js +0 -10
  578. package/dist/esm/types/data-structures/binary-tree/index.js.map +0 -1
  579. package/dist/esm/types/data-structures/binary-tree/red-black-tree.d.ts +0 -3
  580. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js +0 -2
  581. package/dist/esm/types/data-structures/binary-tree/red-black-tree.js.map +0 -1
  582. package/dist/esm/types/data-structures/binary-tree/segment-tree.d.ts +0 -1
  583. package/dist/esm/types/data-structures/binary-tree/segment-tree.js +0 -2
  584. package/dist/esm/types/data-structures/binary-tree/segment-tree.js.map +0 -1
  585. package/dist/esm/types/data-structures/binary-tree/tree-counter.d.ts +0 -2
  586. package/dist/esm/types/data-structures/binary-tree/tree-counter.js +0 -2
  587. package/dist/esm/types/data-structures/binary-tree/tree-counter.js.map +0 -1
  588. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -2
  589. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js +0 -2
  590. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.js.map +0 -1
  591. package/dist/esm/types/data-structures/graph/abstract-graph.js +0 -2
  592. package/dist/esm/types/data-structures/graph/abstract-graph.js.map +0 -1
  593. package/dist/esm/types/data-structures/graph/directed-graph.d.ts +0 -1
  594. package/dist/esm/types/data-structures/graph/directed-graph.js +0 -2
  595. package/dist/esm/types/data-structures/graph/directed-graph.js.map +0 -1
  596. package/dist/esm/types/data-structures/graph/index.d.ts +0 -3
  597. package/dist/esm/types/data-structures/graph/index.js +0 -4
  598. package/dist/esm/types/data-structures/graph/index.js.map +0 -1
  599. package/dist/esm/types/data-structures/graph/map-graph.d.ts +0 -1
  600. package/dist/esm/types/data-structures/graph/map-graph.js +0 -2
  601. package/dist/esm/types/data-structures/graph/map-graph.js.map +0 -1
  602. package/dist/esm/types/data-structures/graph/undirected-graph.d.ts +0 -1
  603. package/dist/esm/types/data-structures/graph/undirected-graph.js +0 -2
  604. package/dist/esm/types/data-structures/graph/undirected-graph.js.map +0 -1
  605. package/dist/esm/types/data-structures/hash/hash-map.d.ts +0 -19
  606. package/dist/esm/types/data-structures/hash/hash-map.js +0 -2
  607. package/dist/esm/types/data-structures/hash/hash-map.js.map +0 -1
  608. package/dist/esm/types/data-structures/hash/index.d.ts +0 -2
  609. package/dist/esm/types/data-structures/hash/index.js +0 -2
  610. package/dist/esm/types/data-structures/hash/index.js.map +0 -1
  611. package/dist/esm/types/data-structures/heap/heap.d.ts +0 -5
  612. package/dist/esm/types/data-structures/heap/heap.js +0 -2
  613. package/dist/esm/types/data-structures/heap/heap.js.map +0 -1
  614. package/dist/esm/types/data-structures/heap/index.d.ts +0 -1
  615. package/dist/esm/types/data-structures/heap/index.js +0 -2
  616. package/dist/esm/types/data-structures/heap/index.js.map +0 -1
  617. package/dist/esm/types/data-structures/heap/max-heap.d.ts +0 -1
  618. package/dist/esm/types/data-structures/heap/max-heap.js +0 -2
  619. package/dist/esm/types/data-structures/heap/max-heap.js.map +0 -1
  620. package/dist/esm/types/data-structures/heap/min-heap.d.ts +0 -1
  621. package/dist/esm/types/data-structures/heap/min-heap.js +0 -2
  622. package/dist/esm/types/data-structures/heap/min-heap.js.map +0 -1
  623. package/dist/esm/types/data-structures/index.d.ts +0 -12
  624. package/dist/esm/types/data-structures/index.js +0 -13
  625. package/dist/esm/types/data-structures/index.js.map +0 -1
  626. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -2
  627. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js +0 -2
  628. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.js.map +0 -1
  629. package/dist/esm/types/data-structures/linked-list/index.d.ts +0 -3
  630. package/dist/esm/types/data-structures/linked-list/index.js +0 -4
  631. package/dist/esm/types/data-structures/linked-list/index.js.map +0 -1
  632. package/dist/esm/types/data-structures/linked-list/singly-linked-list.d.ts +0 -2
  633. package/dist/esm/types/data-structures/linked-list/singly-linked-list.js +0 -2
  634. package/dist/esm/types/data-structures/linked-list/singly-linked-list.js.map +0 -1
  635. package/dist/esm/types/data-structures/linked-list/skip-linked-list.d.ts +0 -4
  636. package/dist/esm/types/data-structures/linked-list/skip-linked-list.js +0 -2
  637. package/dist/esm/types/data-structures/linked-list/skip-linked-list.js.map +0 -1
  638. package/dist/esm/types/data-structures/matrix/index.d.ts +0 -2
  639. package/dist/esm/types/data-structures/matrix/index.js +0 -3
  640. package/dist/esm/types/data-structures/matrix/index.js.map +0 -1
  641. package/dist/esm/types/data-structures/matrix/matrix.d.ts +0 -7
  642. package/dist/esm/types/data-structures/matrix/matrix.js +0 -2
  643. package/dist/esm/types/data-structures/matrix/matrix.js.map +0 -1
  644. package/dist/esm/types/data-structures/matrix/navigator.d.ts +0 -14
  645. package/dist/esm/types/data-structures/matrix/navigator.js +0 -2
  646. package/dist/esm/types/data-structures/matrix/navigator.js.map +0 -1
  647. package/dist/esm/types/data-structures/priority-queue/index.d.ts +0 -3
  648. package/dist/esm/types/data-structures/priority-queue/index.js +0 -4
  649. package/dist/esm/types/data-structures/priority-queue/index.js.map +0 -1
  650. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -1
  651. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js +0 -2
  652. package/dist/esm/types/data-structures/priority-queue/max-priority-queue.js.map +0 -1
  653. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -1
  654. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js +0 -2
  655. package/dist/esm/types/data-structures/priority-queue/min-priority-queue.js.map +0 -1
  656. package/dist/esm/types/data-structures/priority-queue/priority-queue.d.ts +0 -2
  657. package/dist/esm/types/data-structures/priority-queue/priority-queue.js +0 -2
  658. package/dist/esm/types/data-structures/priority-queue/priority-queue.js.map +0 -1
  659. package/dist/esm/types/data-structures/queue/deque.d.ts +0 -4
  660. package/dist/esm/types/data-structures/queue/deque.js +0 -2
  661. package/dist/esm/types/data-structures/queue/deque.js.map +0 -1
  662. package/dist/esm/types/data-structures/queue/index.d.ts +0 -2
  663. package/dist/esm/types/data-structures/queue/index.js +0 -3
  664. package/dist/esm/types/data-structures/queue/index.js.map +0 -1
  665. package/dist/esm/types/data-structures/queue/queue.d.ts +0 -4
  666. package/dist/esm/types/data-structures/queue/queue.js +0 -2
  667. package/dist/esm/types/data-structures/queue/queue.js.map +0 -1
  668. package/dist/esm/types/data-structures/stack/index.d.ts +0 -1
  669. package/dist/esm/types/data-structures/stack/index.js +0 -2
  670. package/dist/esm/types/data-structures/stack/index.js.map +0 -1
  671. package/dist/esm/types/data-structures/stack/stack.d.ts +0 -2
  672. package/dist/esm/types/data-structures/stack/stack.js +0 -2
  673. package/dist/esm/types/data-structures/stack/stack.js.map +0 -1
  674. package/dist/esm/types/data-structures/tree/index.d.ts +0 -1
  675. package/dist/esm/types/data-structures/tree/index.js +0 -2
  676. package/dist/esm/types/data-structures/tree/index.js.map +0 -1
  677. package/dist/esm/types/data-structures/tree/tree.d.ts +0 -1
  678. package/dist/esm/types/data-structures/tree/tree.js +0 -2
  679. package/dist/esm/types/data-structures/tree/tree.js.map +0 -1
  680. package/dist/esm/types/data-structures/trie/index.d.ts +0 -1
  681. package/dist/esm/types/data-structures/trie/index.js +0 -2
  682. package/dist/esm/types/data-structures/trie/index.js.map +0 -1
  683. package/dist/esm/types/data-structures/trie/trie.d.ts +0 -4
  684. package/dist/esm/types/data-structures/trie/trie.js +0 -2
  685. package/dist/esm/types/data-structures/trie/trie.js.map +0 -1
  686. package/dist/esm/types/index.d.ts +0 -3
  687. package/dist/esm/types/index.js +0 -4
  688. package/dist/esm/types/index.js.map +0 -1
  689. package/dist/esm/types/utils/index.d.ts +0 -2
  690. package/dist/esm/types/utils/index.js +0 -3
  691. package/dist/esm/types/utils/index.js.map +0 -1
  692. package/dist/esm/types/utils/utils.d.ts +0 -21
  693. package/dist/esm/types/utils/utils.js +0 -2
  694. package/dist/esm/types/utils/utils.js.map +0 -1
  695. package/dist/esm/types/utils/validate-type.d.ts +0 -19
  696. package/dist/esm/types/utils/validate-type.js +0 -2
  697. package/dist/esm/types/utils/validate-type.js.map +0 -1
  698. package/dist/esm/utils/index.d.ts +0 -2
  699. package/dist/esm/utils/index.js +0 -3
  700. package/dist/esm/utils/index.js.map +0 -1
  701. package/dist/esm/utils/number.d.ts +0 -14
  702. package/dist/esm/utils/number.js +0 -21
  703. package/dist/esm/utils/number.js.map +0 -1
  704. package/dist/esm/utils/utils.js +0 -324
  705. package/dist/esm/utils/utils.js.map +0 -1
  706. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +0 -71
  707. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +0 -81
  708. package/tsconfig-cjs.json +0 -14
  709. package/tsconfig-esm.json +0 -14
  710. /package/dist/{cjs → types}/common/index.d.ts +0 -0
  711. /package/dist/{cjs → types}/data-structures/base/index.d.ts +0 -0
  712. /package/dist/{cjs → types}/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  713. /package/dist/{cjs → types}/data-structures/binary-tree/index.d.ts +0 -0
  714. /package/dist/{cjs → types}/data-structures/binary-tree/segment-tree.d.ts +0 -0
  715. /package/dist/{cjs → types}/data-structures/graph/index.d.ts +0 -0
  716. /package/dist/{cjs → types}/data-structures/hash/index.d.ts +0 -0
  717. /package/dist/{cjs → types}/data-structures/heap/index.d.ts +0 -0
  718. /package/dist/{cjs → types}/data-structures/index.d.ts +0 -0
  719. /package/dist/{cjs → types}/data-structures/linked-list/index.d.ts +0 -0
  720. /package/dist/{cjs → types}/data-structures/matrix/index.d.ts +0 -0
  721. /package/dist/{cjs → types}/data-structures/matrix/matrix.d.ts +0 -0
  722. /package/dist/{cjs → types}/data-structures/matrix/navigator.d.ts +0 -0
  723. /package/dist/{cjs → types}/data-structures/priority-queue/index.d.ts +0 -0
  724. /package/dist/{cjs → types}/data-structures/queue/index.d.ts +0 -0
  725. /package/dist/{cjs → types}/data-structures/stack/index.d.ts +0 -0
  726. /package/dist/{cjs → types}/data-structures/tree/index.d.ts +0 -0
  727. /package/dist/{cjs → types}/data-structures/tree/tree.d.ts +0 -0
  728. /package/dist/{cjs → types}/data-structures/trie/index.d.ts +0 -0
  729. /package/dist/{cjs → types}/index.d.ts +0 -0
  730. /package/dist/{cjs → types}/interfaces/doubly-linked-list.d.ts +0 -0
  731. /package/dist/{cjs → types}/interfaces/heap.d.ts +0 -0
  732. /package/dist/{cjs → types}/interfaces/index.d.ts +0 -0
  733. /package/dist/{cjs → types}/interfaces/navigator.d.ts +0 -0
  734. /package/dist/{cjs → types}/interfaces/priority-queue.d.ts +0 -0
  735. /package/dist/{cjs → types}/interfaces/segment-tree.d.ts +0 -0
  736. /package/dist/{cjs → types}/interfaces/singly-linked-list.d.ts +0 -0
  737. /package/dist/{cjs → types}/types/common.d.ts +0 -0
  738. /package/dist/{cjs → types}/types/data-structures/base/index.d.ts +0 -0
  739. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-counter.d.ts +0 -0
  740. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -0
  741. /package/dist/{cjs → types}/types/data-structures/binary-tree/avl-tree.d.ts +0 -0
  742. /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -0
  743. /package/dist/{cjs → types}/types/data-structures/binary-tree/binary-tree.d.ts +0 -0
  744. /package/dist/{cjs → types}/types/data-structures/binary-tree/bst.d.ts +0 -0
  745. /package/dist/{cjs → types}/types/data-structures/binary-tree/index.d.ts +0 -0
  746. /package/dist/{cjs → types}/types/data-structures/binary-tree/red-black-tree.d.ts +0 -0
  747. /package/dist/{cjs → types}/types/data-structures/binary-tree/segment-tree.d.ts +0 -0
  748. /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-counter.d.ts +0 -0
  749. /package/dist/{cjs → types}/types/data-structures/binary-tree/tree-multi-map.d.ts +0 -0
  750. /package/dist/{cjs → types}/types/data-structures/graph/directed-graph.d.ts +0 -0
  751. /package/dist/{cjs → types}/types/data-structures/graph/index.d.ts +0 -0
  752. /package/dist/{cjs → types}/types/data-structures/graph/map-graph.d.ts +0 -0
  753. /package/dist/{cjs → types}/types/data-structures/graph/undirected-graph.d.ts +0 -0
  754. /package/dist/{cjs → types}/types/data-structures/hash/hash-map.d.ts +0 -0
  755. /package/dist/{cjs → types}/types/data-structures/hash/index.d.ts +0 -0
  756. /package/dist/{cjs → types}/types/data-structures/heap/heap.d.ts +0 -0
  757. /package/dist/{cjs → types}/types/data-structures/heap/index.d.ts +0 -0
  758. /package/dist/{cjs → types}/types/data-structures/heap/max-heap.d.ts +0 -0
  759. /package/dist/{cjs → types}/types/data-structures/heap/min-heap.d.ts +0 -0
  760. /package/dist/{cjs → types}/types/data-structures/index.d.ts +0 -0
  761. /package/dist/{cjs → types}/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -0
  762. /package/dist/{cjs → types}/types/data-structures/linked-list/index.d.ts +0 -0
  763. /package/dist/{cjs → types}/types/data-structures/linked-list/singly-linked-list.d.ts +0 -0
  764. /package/dist/{cjs → types}/types/data-structures/linked-list/skip-linked-list.d.ts +0 -0
  765. /package/dist/{cjs → types}/types/data-structures/matrix/index.d.ts +0 -0
  766. /package/dist/{cjs → types}/types/data-structures/matrix/matrix.d.ts +0 -0
  767. /package/dist/{cjs → types}/types/data-structures/matrix/navigator.d.ts +0 -0
  768. /package/dist/{cjs → types}/types/data-structures/priority-queue/index.d.ts +0 -0
  769. /package/dist/{cjs → types}/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -0
  770. /package/dist/{cjs → types}/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -0
  771. /package/dist/{cjs → types}/types/data-structures/priority-queue/priority-queue.d.ts +0 -0
  772. /package/dist/{cjs → types}/types/data-structures/queue/deque.d.ts +0 -0
  773. /package/dist/{cjs → types}/types/data-structures/queue/index.d.ts +0 -0
  774. /package/dist/{cjs → types}/types/data-structures/queue/queue.d.ts +0 -0
  775. /package/dist/{cjs → types}/types/data-structures/stack/index.d.ts +0 -0
  776. /package/dist/{cjs → types}/types/data-structures/stack/stack.d.ts +0 -0
  777. /package/dist/{cjs → types}/types/data-structures/tree/index.d.ts +0 -0
  778. /package/dist/{cjs → types}/types/data-structures/tree/tree.d.ts +0 -0
  779. /package/dist/{cjs → types}/types/data-structures/trie/index.d.ts +0 -0
  780. /package/dist/{cjs → types}/types/data-structures/trie/trie.d.ts +0 -0
  781. /package/dist/{cjs → types}/types/index.d.ts +0 -0
  782. /package/dist/{cjs → types}/types/utils/index.d.ts +0 -0
  783. /package/dist/{cjs → types}/types/utils/validate-type.d.ts +0 -0
  784. /package/dist/{cjs → types}/utils/index.d.ts +0 -0
  785. /package/dist/{cjs → types}/utils/number.d.ts +0 -0
@@ -1,867 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractGraph = exports.AbstractEdge = exports.AbstractVertex = void 0;
4
- const utils_1 = require("../../utils");
5
- const base_1 = require("../base");
6
- const heap_1 = require("../heap");
7
- const queue_1 = require("../queue");
8
- class AbstractVertex {
9
- /**
10
- * The function is a protected constructor that takes an key and an optional value as parameters.
11
- * @param {VertexKey} key - The `key` parameter is of type `VertexKey` and represents the identifier of the vertex. It is
12
- * used to uniquely identify the vertex object.
13
- * @param {V} [value] - The parameter "value" is an optional parameter of type V. It is used to assign a value to the
14
- * vertex. If no value is provided, it will be set to undefined.
15
- */
16
- constructor(key, value) {
17
- this.key = key;
18
- this.value = value;
19
- }
20
- }
21
- exports.AbstractVertex = AbstractVertex;
22
- class AbstractEdge {
23
- /**
24
- * The above function is a protected constructor that initializes the weight, value, and hash code properties of an
25
- * object.
26
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
27
- * a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
28
- * will be assigned.
29
- * @param {VO} [value] - The `value` parameter is of type `VO`, which means it can be any type. It is an optional parameter,
30
- * meaning it can be omitted when creating an instance of the class.
31
- */
32
- constructor(weight, value) {
33
- this.weight = weight !== undefined ? weight : 1;
34
- this.value = value;
35
- this._hashCode = (0, utils_1.uuidV4)();
36
- }
37
- get hashCode() {
38
- return this._hashCode;
39
- }
40
- }
41
- exports.AbstractEdge = AbstractEdge;
42
- class AbstractGraph extends base_1.IterableEntryBase {
43
- constructor() {
44
- super();
45
- this._vertexMap = new Map();
46
- }
47
- get vertexMap() {
48
- return this._vertexMap;
49
- }
50
- set vertexMap(v) {
51
- this._vertexMap = v;
52
- }
53
- get size() {
54
- return this._vertexMap.size;
55
- }
56
- /**
57
- * Time Complexity: O(1) - Constant time for Map lookup.
58
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
59
- *
60
- * The function "getVertex" returns the vertex with the specified ID or undefined if it doesn't exist.
61
- * @param {VertexKey} vertexKey - The `vertexKey` parameter is the identifier of the vertex that you want to retrieve from
62
- * the `_vertexMap` map.
63
- * @returns The method `getVertex` returns the vertex with the specified `vertexKey` if it exists in the `_vertexMap`
64
- * map. If the vertex does not exist, it returns `undefined`.
65
- */
66
- getVertex(vertexKey) {
67
- return this._vertexMap.get(vertexKey) || undefined;
68
- }
69
- /**
70
- * Time Complexity: O(1) - Constant time for Map lookup.
71
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
72
- *
73
- * The function checks if a vertex exists in a graph.
74
- * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
75
- * (`VertexKey`).
76
- * @returns a boolean value.
77
- */
78
- hasVertex(vertexOrKey) {
79
- return this._vertexMap.has(this._getVertexKey(vertexOrKey));
80
- }
81
- /**
82
- * Time Complexity: O(1) - Constant time for Map operations.
83
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
84
- */
85
- addVertex(keyOrVertex, value) {
86
- if (keyOrVertex instanceof AbstractVertex) {
87
- return this._addVertex(keyOrVertex);
88
- }
89
- else {
90
- const newVertex = this.createVertex(keyOrVertex, value);
91
- return this._addVertex(newVertex);
92
- }
93
- }
94
- isVertexKey(potentialKey) {
95
- const potentialKeyType = typeof potentialKey;
96
- return potentialKeyType === 'string' || potentialKeyType === 'number';
97
- }
98
- /**
99
- * Time Complexity: O(K), where K is the number of vertexMap to be removed.
100
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
101
- *
102
- * The function removes all vertexMap from a graph and returns a boolean indicating if any vertexMap were removed.
103
- * @param {VO[] | VertexKey[]} vertexMap - The `vertexMap` parameter can be either an array of vertexMap (`VO[]`) or an array
104
- * of vertex IDs (`VertexKey[]`).
105
- * @returns a boolean value. It returns true if at least one vertex was successfully removed, and false if no vertexMap
106
- * were removed.
107
- */
108
- removeManyVertices(vertexMap) {
109
- const removed = [];
110
- for (const v of vertexMap) {
111
- removed.push(this.deleteVertex(v));
112
- }
113
- return removed.length > 0;
114
- }
115
- /**
116
- * Time Complexity: O(1) - Depends on the implementation in the concrete class.
117
- * Space Complexity: O(1) - Depends on the implementation in the concrete class.
118
- *
119
- * The function checks if there is an edge between two vertexMap and returns a boolean value indicating the result.
120
- * @param {VertexKey | VO} v1 - The parameter v1 can be either a VertexKey or a VO. A VertexKey represents the unique
121
- * identifier of a vertex in a graph, while VO represents the type of the vertex object itself.
122
- * @param {VertexKey | VO} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
123
- * `VertexKey` or a `VO` type, which represents the type of the vertex.
124
- * @returns A boolean value is being returned.
125
- */
126
- hasEdge(v1, v2) {
127
- const edge = this.getEdge(v1, v2);
128
- return !!edge;
129
- }
130
- /**
131
- * Time Complexity: O(1) - Depends on the implementation in the concrete class.
132
- * Space Complexity: O(1) - Depends on the implementation in the concrete class.
133
- */
134
- addEdge(srcOrEdge, dest, weight, value) {
135
- if (srcOrEdge instanceof AbstractEdge) {
136
- return this._addEdge(srcOrEdge);
137
- }
138
- else {
139
- if (dest instanceof AbstractVertex || typeof dest === 'string' || typeof dest === 'number') {
140
- if (!(this.hasVertex(srcOrEdge) && this.hasVertex(dest)))
141
- return false;
142
- if (srcOrEdge instanceof AbstractVertex)
143
- srcOrEdge = srcOrEdge.key;
144
- if (dest instanceof AbstractVertex)
145
- dest = dest.key;
146
- const newEdge = this.createEdge(srcOrEdge, dest, weight, value);
147
- return this._addEdge(newEdge);
148
- }
149
- else {
150
- throw new Error('dest must be a Vertex or vertex key while srcOrEdge is an Edge');
151
- }
152
- }
153
- }
154
- /**
155
- * Time Complexity: O(1) - Constant time for Map and Edge operations.
156
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
157
- *
158
- * The function sets the weight of an edge between two vertexMap in a graph.
159
- * @param {VertexKey | VO} srcOrKey - The `srcOrKey` parameter can be either a `VertexKey` or a `VO` object. It represents
160
- * the source vertex of the edge.
161
- * @param {VertexKey | VO} destOrKey - The `destOrKey` parameter represents the destination vertex of the edge. It can be
162
- * either a `VertexKey` or a vertex object `VO`.
163
- * @param {number} weight - The weight parameter represents the weight of the edge between the source vertex (srcOrKey)
164
- * and the destination vertex (destOrKey).
165
- * @returns a boolean value. If the edge exists between the source and destination vertexMap, the function will update
166
- * the weight of the edge and return true. If the edge does not exist, the function will return false.
167
- */
168
- setEdgeWeight(srcOrKey, destOrKey, weight) {
169
- const edge = this.getEdge(srcOrKey, destOrKey);
170
- if (edge) {
171
- edge.weight = weight;
172
- return true;
173
- }
174
- else {
175
- return false;
176
- }
177
- }
178
- /**
179
- * Time Complexity: O(P), where P is the number of paths found (in the worst case, exploring all paths).
180
- * Space Complexity: O(P) - Linear space, where P is the number of paths found.
181
- *
182
- * The function `getAllPathsBetween` finds all paths between two vertexMap in a graph using depth-first search.
183
- * @param {VO | VertexKey} v1 - The parameter `v1` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
184
- * It is the starting vertex for finding paths.
185
- * @param {VO | VertexKey} v2 - The parameter `v2` represents either a vertex object (`VO`) or a vertex ID (`VertexKey`).
186
- * @param limit - The count of limitation of result array.
187
- * @returns The function `getAllPathsBetween` returns an array of arrays of vertexMap (`VO[][]`).
188
- */
189
- getAllPathsBetween(v1, v2, limit = 1000) {
190
- const paths = [];
191
- const vertex1 = this._getVertex(v1);
192
- const vertex2 = this._getVertex(v2);
193
- if (!(vertex1 && vertex2)) {
194
- return [];
195
- }
196
- const stack = [];
197
- stack.push({ vertex: vertex1, path: [vertex1] });
198
- while (stack.length > 0) {
199
- const { vertex, path } = stack.pop();
200
- if (vertex === vertex2) {
201
- paths.push(path);
202
- if (paths.length >= limit)
203
- return paths;
204
- }
205
- const neighbors = this.getNeighbors(vertex);
206
- for (const neighbor of neighbors) {
207
- if (!path.includes(neighbor)) {
208
- const newPath = [...path, neighbor];
209
- stack.push({ vertex: neighbor, path: newPath });
210
- }
211
- }
212
- }
213
- return paths;
214
- }
215
- /**
216
- * Time Complexity: O(L), where L is the length of the path.
217
- * Space Complexity: O(1) - Constant space.
218
- *
219
- * The function calculates the sum of weights along a given path.
220
- * @param {VO[]} path - An array of vertexMap (VO) representing a path in a graph.
221
- * @returns The function `getPathSumWeight` returns the sum of the weights of the edgeMap in the given path.
222
- */
223
- getPathSumWeight(path) {
224
- var _a;
225
- let sum = 0;
226
- for (let i = 0; i < path.length; i++) {
227
- sum += ((_a = this.getEdge(path[i], path[i + 1])) === null || _a === void 0 ? void 0 : _a.weight) || 0;
228
- }
229
- return sum;
230
- }
231
- /**
232
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
233
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
234
- *
235
- * The function `getMinCostBetween` calculates the minimum cost between two vertexMap in a graph, either based on edge
236
- * weights or using a breadth-first search algorithm.
237
- * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex or its ID.
238
- * @param {VO | VertexKey} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
239
- * you want to find the minimum cost or weight from the source vertex `v1`.
240
- * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edgeMap have weights.
241
- * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
242
- * the edgeMap. If isWeight is set to false or not provided, the function will calculate the
243
- * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertexMap (`v1`
244
- * and `v2`). If the `isWeight` parameter is `true`, it calculates the minimum weight among all paths between the
245
- * vertexMap. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
246
- * minimum number of
247
- */
248
- getMinCostBetween(v1, v2, isWeight) {
249
- if (isWeight === undefined)
250
- isWeight = false;
251
- if (isWeight) {
252
- const allPaths = this.getAllPathsBetween(v1, v2);
253
- let min = Number.MAX_SAFE_INTEGER;
254
- for (const path of allPaths) {
255
- min = Math.min(this.getPathSumWeight(path), min);
256
- }
257
- return min;
258
- }
259
- else {
260
- // BFS
261
- const vertex2 = this._getVertex(v2);
262
- const vertex1 = this._getVertex(v1);
263
- if (!(vertex1 && vertex2)) {
264
- return undefined;
265
- }
266
- const visited = new Map();
267
- const queue = new queue_1.Queue([vertex1]);
268
- visited.set(vertex1, true);
269
- let cost = 0;
270
- while (queue.length > 0) {
271
- for (let i = 0; i < queue.length; i++) {
272
- const cur = queue.shift();
273
- if (cur === vertex2) {
274
- return cost;
275
- }
276
- // TODO consider optimizing to AbstractGraph
277
- if (cur !== undefined) {
278
- const neighbors = this.getNeighbors(cur);
279
- for (const neighbor of neighbors) {
280
- if (!visited.has(neighbor)) {
281
- visited.set(neighbor, true);
282
- queue.push(neighbor);
283
- }
284
- }
285
- }
286
- }
287
- cost++;
288
- }
289
- return undefined;
290
- }
291
- }
292
- /**
293
- * Time Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
294
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm or DFS).
295
- *
296
- * The function `getMinPathBetween` returns the minimum path between two vertexMap in a graph, either based on weight or
297
- * using a breadth-first search algorithm.
298
- * @param {VO | VertexKey} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
299
- * object (`VO`) or a vertex ID (`VertexKey`).
300
- * @param {VO | VertexKey} v2 - VO | VertexKey - The second vertex or vertex ID between which we want to find the minimum
301
- * path.
302
- * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edgeMap in finding the
303
- * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
304
- * to false, the function will use breadth-first search (BFS) to find the minimum path.
305
- * @param isDFS - If set to true, it enforces the use of getAllPathsBetween to first obtain all possible paths,
306
- * followed by iterative computation of the shortest path. This approach may result in exponential time complexity,
307
- * so the default method is to use the Dijkstra algorithm to obtain the shortest weighted path.
308
- * @returns The function `getMinPathBetween` returns an array of vertexMap (`VO[]`) representing the minimum path between
309
- * two vertexMap (`v1` and `v2`). If there is no path between the vertexMap, it returns `undefined`.
310
- */
311
- getMinPathBetween(v1, v2, isWeight, isDFS = false) {
312
- var _a, _b;
313
- if (isWeight === undefined)
314
- isWeight = false;
315
- if (isWeight) {
316
- if (isDFS) {
317
- const allPaths = this.getAllPathsBetween(v1, v2, 10000);
318
- let min = Number.MAX_SAFE_INTEGER;
319
- let minIndex = -1;
320
- let index = 0;
321
- for (const path of allPaths) {
322
- const pathSumWeight = this.getPathSumWeight(path);
323
- if (pathSumWeight < min) {
324
- min = pathSumWeight;
325
- minIndex = index;
326
- }
327
- index++;
328
- }
329
- return allPaths[minIndex] || undefined;
330
- }
331
- else {
332
- return (_b = (_a = this.dijkstra(v1, v2, true, true)) === null || _a === void 0 ? void 0 : _a.minPath) !== null && _b !== void 0 ? _b : [];
333
- }
334
- }
335
- else {
336
- // DFS
337
- let minPath = [];
338
- const vertex1 = this._getVertex(v1);
339
- const vertex2 = this._getVertex(v2);
340
- if (!(vertex1 && vertex2))
341
- return [];
342
- const dfs = (cur, dest, visiting, path) => {
343
- visiting.add(cur);
344
- if (cur === dest) {
345
- minPath = [vertex1, ...path];
346
- return;
347
- }
348
- const neighbors = this.getNeighbors(cur);
349
- for (const neighbor of neighbors) {
350
- if (!visiting.has(neighbor)) {
351
- path.push(neighbor);
352
- dfs(neighbor, dest, visiting, path);
353
- path.pop();
354
- }
355
- }
356
- visiting.delete(cur);
357
- };
358
- dfs(vertex1, vertex2, new Set(), []);
359
- return minPath;
360
- }
361
- }
362
- /**
363
- * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
364
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
365
- *
366
- * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertexMap in
367
- * a graph without using a heap data structure.
368
- * @param {VO | VertexKey} src - The source vertex from which to start the Dijkstra's algorithm. It can be either a
369
- * vertex object or a vertex ID.
370
- * @param {VO | VertexKey | undefined} [dest] - The `dest` parameter in the `dijkstraWithoutHeap` function is an optional
371
- * parameter that specifies the destination vertex for the Dijkstra algorithm. It can be either a vertex object or its
372
- * identifier. If no destination is provided, the value is set to `undefined`.
373
- * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
374
- * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
375
- * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
376
- * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
377
- * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
378
- * shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
379
- * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<VO>`.
380
- */
381
- dijkstraWithoutHeap(src, dest = undefined, getMinDist = false, genPaths = false) {
382
- let minDist = Number.MAX_SAFE_INTEGER;
383
- let minDest = undefined;
384
- let minPath = [];
385
- const paths = [];
386
- const vertexMap = this._vertexMap;
387
- const distMap = new Map();
388
- const seen = new Set();
389
- const preMap = new Map(); // predecessor
390
- const srcVertex = this._getVertex(src);
391
- const destVertex = dest ? this._getVertex(dest) : undefined;
392
- if (!srcVertex) {
393
- return undefined;
394
- }
395
- for (const vertex of vertexMap) {
396
- const vertexOrKey = vertex[1];
397
- if (vertexOrKey instanceof AbstractVertex)
398
- distMap.set(vertexOrKey, Number.MAX_SAFE_INTEGER);
399
- }
400
- distMap.set(srcVertex, 0);
401
- preMap.set(srcVertex, undefined);
402
- const getMinOfNoSeen = () => {
403
- let min = Number.MAX_SAFE_INTEGER;
404
- let minV = undefined;
405
- for (const [key, value] of distMap) {
406
- if (!seen.has(key)) {
407
- if (value < min) {
408
- min = value;
409
- minV = key;
410
- }
411
- }
412
- }
413
- return minV;
414
- };
415
- const getPaths = (minV) => {
416
- for (const vertex of vertexMap) {
417
- const vertexOrKey = vertex[1];
418
- if (vertexOrKey instanceof AbstractVertex) {
419
- const path = [vertexOrKey];
420
- let parent = preMap.get(vertexOrKey);
421
- while (parent) {
422
- path.push(parent);
423
- parent = preMap.get(parent);
424
- }
425
- const reversed = path.reverse();
426
- if (vertex[1] === minV)
427
- minPath = reversed;
428
- paths.push(reversed);
429
- }
430
- }
431
- };
432
- for (let i = 1; i < vertexMap.size; i++) {
433
- const cur = getMinOfNoSeen();
434
- if (cur) {
435
- seen.add(cur);
436
- if (destVertex && destVertex === cur) {
437
- if (getMinDist) {
438
- minDist = distMap.get(destVertex) || Number.MAX_SAFE_INTEGER;
439
- }
440
- if (genPaths) {
441
- getPaths(destVertex);
442
- }
443
- return { distMap, preMap, seen, paths, minDist, minPath };
444
- }
445
- const neighbors = this.getNeighbors(cur);
446
- for (const neighbor of neighbors) {
447
- if (!seen.has(neighbor)) {
448
- const edge = this.getEdge(cur, neighbor);
449
- if (edge) {
450
- const curFromMap = distMap.get(cur);
451
- const neighborFromMap = distMap.get(neighbor);
452
- // TODO after no-non-undefined-assertion not ensure the logic
453
- if (curFromMap !== undefined && neighborFromMap !== undefined) {
454
- if (edge.weight + curFromMap < neighborFromMap) {
455
- distMap.set(neighbor, edge.weight + curFromMap);
456
- preMap.set(neighbor, cur);
457
- }
458
- }
459
- }
460
- }
461
- }
462
- }
463
- }
464
- if (getMinDist)
465
- distMap.forEach((d, v) => {
466
- if (v !== srcVertex) {
467
- if (d < minDist) {
468
- minDist = d;
469
- if (genPaths)
470
- minDest = v;
471
- }
472
- }
473
- });
474
- if (genPaths)
475
- getPaths(minDest);
476
- return { distMap, preMap, seen, paths, minDist, minPath };
477
- }
478
- /**
479
- * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
480
- * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
481
- *
482
- * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
483
- * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
484
- * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
485
- * @param {VO | VertexKey} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
486
- * start. It can be either a vertex object or a vertex ID.
487
- * @param {VO | VertexKey | undefined} [dest] - The `dest` parameter is the destination vertex or vertex ID. It specifies the
488
- * vertex to which the shortest path is calculated from the source vertex. If no destination is provided, the algorithm
489
- * will calculate the shortest paths to all other vertexMap from the source vertex.
490
- * @param {boolean} [getMinDist] - The `getMinDist` parameter is a boolean flag that determines whether the minimum
491
- * distance from the source vertex to the destination vertex should be calculated and returned in the result. If
492
- * `getMinDist` is set to `true`, the `minDist` property in the result will contain the minimum distance
493
- * @param {boolean} [genPaths] - The `genPaths` parameter is a boolean flag that determines whether or not to generate
494
- * paths in the Dijkstra algorithm. If `genPaths` is set to `true`, the algorithm will calculate and return the
495
- * shortest paths from the source vertex to all other vertexMap in the graph. If `genPaths
496
- * @returns The function `dijkstra` returns an object of type `DijkstraResult<VO>`.
497
- */
498
- dijkstra(src, dest = undefined, getMinDist = false, genPaths = false) {
499
- var _a;
500
- let minDist = Number.MAX_SAFE_INTEGER;
501
- let minDest = undefined;
502
- let minPath = [];
503
- const paths = [];
504
- const vertexMap = this._vertexMap;
505
- const distMap = new Map();
506
- const seen = new Set();
507
- const preMap = new Map(); // predecessor
508
- const srcVertex = this._getVertex(src);
509
- const destVertex = dest ? this._getVertex(dest) : undefined;
510
- if (!srcVertex)
511
- return undefined;
512
- for (const vertex of vertexMap) {
513
- const vertexOrKey = vertex[1];
514
- if (vertexOrKey instanceof AbstractVertex)
515
- distMap.set(vertexOrKey, Number.MAX_SAFE_INTEGER);
516
- }
517
- const heap = new heap_1.Heap([], { comparator: (a, b) => a.key - b.key });
518
- heap.add({ key: 0, value: srcVertex });
519
- distMap.set(srcVertex, 0);
520
- preMap.set(srcVertex, undefined);
521
- /**
522
- * The function `getPaths` retrieves all paths from vertexMap to a specified minimum vertex.
523
- * @param {VO | undefined} minV - The parameter `minV` is of type `VO | undefined`. It represents the minimum vertex value or
524
- * undefined.
525
- */
526
- const getPaths = (minV) => {
527
- for (const vertex of vertexMap) {
528
- const vertexOrKey = vertex[1];
529
- if (vertexOrKey instanceof AbstractVertex) {
530
- const path = [vertexOrKey];
531
- let parent = preMap.get(vertexOrKey);
532
- while (parent) {
533
- path.push(parent);
534
- parent = preMap.get(parent);
535
- }
536
- const reversed = path.reverse();
537
- if (vertex[1] === minV)
538
- minPath = reversed;
539
- paths.push(reversed);
540
- }
541
- }
542
- };
543
- while (heap.size > 0) {
544
- const curHeapNode = heap.poll();
545
- const dist = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.key;
546
- const cur = curHeapNode === null || curHeapNode === void 0 ? void 0 : curHeapNode.value;
547
- if (dist !== undefined) {
548
- if (cur) {
549
- seen.add(cur);
550
- if (destVertex && destVertex === cur) {
551
- if (getMinDist) {
552
- minDist = distMap.get(destVertex) || Number.MAX_SAFE_INTEGER;
553
- }
554
- if (genPaths) {
555
- getPaths(destVertex);
556
- }
557
- return { distMap, preMap, seen, paths, minDist, minPath };
558
- }
559
- const neighbors = this.getNeighbors(cur);
560
- for (const neighbor of neighbors) {
561
- if (!seen.has(neighbor)) {
562
- const weight = (_a = this.getEdge(cur, neighbor)) === null || _a === void 0 ? void 0 : _a.weight;
563
- if (typeof weight === 'number') {
564
- const distSrcToNeighbor = distMap.get(neighbor);
565
- if (distSrcToNeighbor) {
566
- if (dist + weight < distSrcToNeighbor) {
567
- heap.add({ key: dist + weight, value: neighbor });
568
- preMap.set(neighbor, cur);
569
- distMap.set(neighbor, dist + weight);
570
- }
571
- }
572
- }
573
- }
574
- }
575
- }
576
- }
577
- }
578
- if (getMinDist) {
579
- distMap.forEach((d, v) => {
580
- if (v !== srcVertex) {
581
- if (d < minDist) {
582
- minDist = d;
583
- if (genPaths)
584
- minDest = v;
585
- }
586
- }
587
- });
588
- }
589
- if (genPaths) {
590
- getPaths(minDest);
591
- }
592
- return { distMap, preMap, seen, paths, minDist, minPath };
593
- }
594
- /**
595
- * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
596
- * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
597
- *
598
- * one to rest pairs
599
- * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
600
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
601
- * all other vertexMap in a graph, and optionally detects negative cycles and generates the minimum path.
602
- * @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
603
- * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
604
- * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
605
- * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
606
- * calculate the minimum distance from the source vertex to all other vertexMap in the graph. If `getMin` is set to
607
- * `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
608
- * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertexMap from the source
609
- * vertex.
610
- * @returns The function `bellmanFord` returns an object with the following properties:
611
- */
612
- bellmanFord(src, scanNegativeCycle, getMin, genPath) {
613
- if (getMin === undefined)
614
- getMin = false;
615
- if (genPath === undefined)
616
- genPath = false;
617
- const srcVertex = this._getVertex(src);
618
- const paths = [];
619
- const distMap = new Map();
620
- const preMap = new Map(); // predecessor
621
- let min = Number.MAX_SAFE_INTEGER;
622
- let minPath = [];
623
- // TODO
624
- let hasNegativeCycle;
625
- if (scanNegativeCycle)
626
- hasNegativeCycle = false;
627
- if (!srcVertex)
628
- return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
629
- const vertexMap = this._vertexMap;
630
- const numOfVertices = vertexMap.size;
631
- const edgeMap = this.edgeSet();
632
- const numOfEdges = edgeMap.length;
633
- this._vertexMap.forEach(vertex => {
634
- distMap.set(vertex, Number.MAX_SAFE_INTEGER);
635
- });
636
- distMap.set(srcVertex, 0);
637
- for (let i = 1; i < numOfVertices; ++i) {
638
- for (let j = 0; j < numOfEdges; ++j) {
639
- const ends = this.getEndsOfEdge(edgeMap[j]);
640
- if (ends) {
641
- const [s, d] = ends;
642
- const weight = edgeMap[j].weight;
643
- const sWeight = distMap.get(s);
644
- const dWeight = distMap.get(d);
645
- if (sWeight !== undefined && dWeight !== undefined) {
646
- if (distMap.get(s) !== Number.MAX_SAFE_INTEGER && sWeight + weight < dWeight) {
647
- distMap.set(d, sWeight + weight);
648
- if (genPath)
649
- preMap.set(d, s);
650
- }
651
- }
652
- }
653
- }
654
- }
655
- let minDest = undefined;
656
- if (getMin) {
657
- distMap.forEach((d, v) => {
658
- if (v !== srcVertex) {
659
- if (d < min) {
660
- min = d;
661
- if (genPath)
662
- minDest = v;
663
- }
664
- }
665
- });
666
- }
667
- if (genPath) {
668
- for (const vertex of vertexMap) {
669
- const vertexOrKey = vertex[1];
670
- if (vertexOrKey instanceof AbstractVertex) {
671
- const path = [vertexOrKey];
672
- let parent = preMap.get(vertexOrKey);
673
- while (parent !== undefined) {
674
- path.push(parent);
675
- parent = preMap.get(parent);
676
- }
677
- const reversed = path.reverse();
678
- if (vertex[1] === minDest)
679
- minPath = reversed;
680
- paths.push(reversed);
681
- }
682
- }
683
- }
684
- for (let j = 0; j < numOfEdges; ++j) {
685
- const ends = this.getEndsOfEdge(edgeMap[j]);
686
- if (ends) {
687
- const [s] = ends;
688
- const weight = edgeMap[j].weight;
689
- const sWeight = distMap.get(s);
690
- if (sWeight) {
691
- if (sWeight !== Number.MAX_SAFE_INTEGER && sWeight + weight < sWeight)
692
- hasNegativeCycle = true;
693
- }
694
- }
695
- }
696
- return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
697
- }
698
- /**
699
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
700
- */
701
- /**
702
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
703
- * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
704
- */
705
- /**
706
- * BellmanFord time:O(VE) space:O(VO)
707
- * one to rest pairs
708
- * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
709
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
710
- */
711
- /**
712
- * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
713
- * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
714
- *
715
- * Not support graph with negative weight cycle
716
- * all pairs
717
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
718
- * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertexMap in a
719
- * graph.
720
- * @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
721
- * property is a 2D array of numbers representing the shortest path costs between vertexMap in a graph. The
722
- * `predecessor` property is a 2D array of vertexMap (or `undefined`) representing the predecessor vertexMap in the shortest
723
- * path between vertexMap in the
724
- */
725
- floydWarshall() {
726
- var _a;
727
- const idAndVertices = [...this._vertexMap];
728
- const n = idAndVertices.length;
729
- const costs = [];
730
- const predecessor = [];
731
- // successors
732
- for (let i = 0; i < n; i++) {
733
- costs[i] = [];
734
- predecessor[i] = [];
735
- for (let j = 0; j < n; j++) {
736
- predecessor[i][j] = undefined;
737
- }
738
- }
739
- for (let i = 0; i < n; i++) {
740
- for (let j = 0; j < n; j++) {
741
- costs[i][j] = ((_a = this.getEdge(idAndVertices[i][1], idAndVertices[j][1])) === null || _a === void 0 ? void 0 : _a.weight) || Number.MAX_SAFE_INTEGER;
742
- }
743
- }
744
- for (let k = 0; k < n; k++) {
745
- for (let i = 0; i < n; i++) {
746
- for (let j = 0; j < n; j++) {
747
- if (costs[i][j] > costs[i][k] + costs[k][j]) {
748
- costs[i][j] = costs[i][k] + costs[k][j];
749
- predecessor[i][j] = idAndVertices[k][1];
750
- }
751
- }
752
- }
753
- }
754
- return { costs, predecessor };
755
- }
756
- /**
757
- * O(V+E+C)
758
- * O(V+C)
759
- */
760
- getCycles(isInclude2Cycle = false) {
761
- const cycles = [];
762
- const visited = new Set();
763
- const dfs = (vertex, currentPath, visited) => {
764
- if (visited.has(vertex)) {
765
- if (((!isInclude2Cycle && currentPath.length > 2) || (isInclude2Cycle && currentPath.length >= 2)) &&
766
- currentPath[0] === vertex.key) {
767
- cycles.push([...currentPath]);
768
- }
769
- return;
770
- }
771
- visited.add(vertex);
772
- currentPath.push(vertex.key);
773
- for (const neighbor of this.getNeighbors(vertex)) {
774
- if (neighbor)
775
- dfs(neighbor, currentPath, visited);
776
- }
777
- visited.delete(vertex);
778
- currentPath.pop();
779
- };
780
- for (const vertex of this.vertexMap.values()) {
781
- dfs(vertex, [], visited);
782
- }
783
- // Use a set to eliminate duplicate cycles
784
- const uniqueCycles = new Map();
785
- for (const cycle of cycles) {
786
- const sorted = [...cycle].sort().toString();
787
- if (uniqueCycles.has(sorted))
788
- continue;
789
- else {
790
- uniqueCycles.set(sorted, cycle);
791
- }
792
- }
793
- // Convert the unique cycles back to an array
794
- return [...uniqueCycles].map(cycleString => cycleString[1]);
795
- }
796
- /**
797
- * Time Complexity: O(n)
798
- * Space Complexity: O(n)
799
- *
800
- * The `filter` function iterates over key-value pairs in a data structure and returns an array of
801
- * pairs that satisfy a given predicate.
802
- * @param predicate - The `predicate` parameter is a callback function that takes four arguments:
803
- * `value`, `key`, `index`, and `this`. It is used to determine whether an element should be included
804
- * in the filtered array. The callback function should return `true` if the element should be
805
- * included, and `
806
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
807
- * specify the value of `this` within the `predicate` function. It is used when you want to bind a
808
- * specific object as the context for the `predicate` function. If `thisArg` is provided, it will be
809
- * @returns The `filter` method returns an array of key-value pairs `[VertexKey, V | undefined][]`
810
- * that satisfy the given predicate function.
811
- */
812
- filter(predicate, thisArg) {
813
- const filtered = [];
814
- let index = 0;
815
- for (const [key, value] of this) {
816
- if (predicate.call(thisArg, key, value, index, this)) {
817
- filtered.push([key, value]);
818
- }
819
- index++;
820
- }
821
- return filtered;
822
- }
823
- /**
824
- * Time Complexity: O(n)
825
- * Space Complexity: O(n)
826
- *
827
- * The `map` function iterates over the elements of a collection and applies a callback function to
828
- * each element, returning an array of the results.
829
- * @param callback - The callback parameter is a function that will be called for each element in the
830
- * map. It takes four arguments:
831
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
832
- * specify the value of `this` within the callback function. If `thisArg` is provided, it will be
833
- * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
834
- * @returns The `map` function is returning an array of type `T[]`.
835
- */
836
- map(callback, thisArg) {
837
- const mapped = [];
838
- let index = 0;
839
- for (const [key, value] of this) {
840
- mapped.push(callback.call(thisArg, key, value, index, this));
841
- index++;
842
- }
843
- return mapped;
844
- }
845
- *_getIterator() {
846
- for (const vertex of this._vertexMap.values()) {
847
- yield [vertex.key, vertex.value];
848
- }
849
- }
850
- _addVertex(newVertex) {
851
- if (this.hasVertex(newVertex)) {
852
- return false;
853
- // throw (new Error('Duplicated vertex key is not allowed'));
854
- }
855
- this._vertexMap.set(newVertex.key, newVertex);
856
- return true;
857
- }
858
- _getVertex(vertexOrKey) {
859
- const vertexKey = this._getVertexKey(vertexOrKey);
860
- return this._vertexMap.get(vertexKey) || undefined;
861
- }
862
- _getVertexKey(vertexOrKey) {
863
- return vertexOrKey instanceof AbstractVertex ? vertexOrKey.key : vertexOrKey;
864
- }
865
- }
866
- exports.AbstractGraph = AbstractGraph;
867
- //# sourceMappingURL=abstract-graph.js.map