data-structure-typed 1.17.4 → 1.18.5

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 (293) hide show
  1. package/README.md +193 -66
  2. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  3. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  4. package/backup/recursive-type/src/assets/logo.png +0 -0
  5. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  6. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +3 -0
  7. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +288 -0
  8. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +3 -0
  9. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
  10. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +1502 -0
  11. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +503 -0
  12. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  13. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  14. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  15. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +11 -0
  16. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +110 -0
  17. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +243 -0
  18. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +3 -0
  19. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +55 -0
  20. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +3 -0
  21. package/backup/recursive-type/src/data-structures/diagrams/README.md +5 -0
  22. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +985 -0
  23. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  24. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  25. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  26. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  27. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  28. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  29. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  30. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  31. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  32. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  33. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  34. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  35. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  36. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  37. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +478 -0
  38. package/backup/recursive-type/src/data-structures/graph/index.ts +3 -0
  39. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +293 -0
  40. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +67 -0
  41. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +56 -0
  42. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +3 -0
  43. package/backup/recursive-type/src/data-structures/hash/index.ts +6 -0
  44. package/backup/recursive-type/src/data-structures/hash/pair.ts +3 -0
  45. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +3 -0
  46. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +3 -0
  47. package/backup/recursive-type/src/data-structures/heap/heap.ts +176 -0
  48. package/backup/recursive-type/src/data-structures/heap/index.ts +3 -0
  49. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +31 -0
  50. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +34 -0
  51. package/backup/recursive-type/src/data-structures/index.ts +15 -0
  52. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +42 -0
  53. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +1 -0
  54. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +56 -0
  55. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +1 -0
  56. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +15 -0
  57. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
  58. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +1 -0
  59. package/backup/recursive-type/src/data-structures/interfaces/index.ts +13 -0
  60. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +1 -0
  61. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +1 -0
  62. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +1 -0
  63. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +1 -0
  64. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +1 -0
  65. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +3 -0
  66. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
  67. package/backup/recursive-type/src/data-structures/linked-list/index.ts +3 -0
  68. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +490 -0
  69. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  70. package/backup/recursive-type/src/data-structures/matrix/index.ts +4 -0
  71. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +27 -0
  72. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +208 -0
  73. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +122 -0
  74. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +316 -0
  75. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +3 -0
  76. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
  77. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
  78. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +354 -0
  79. package/backup/recursive-type/src/data-structures/queue/deque.ts +251 -0
  80. package/backup/recursive-type/src/data-structures/queue/index.ts +2 -0
  81. package/backup/recursive-type/src/data-structures/queue/queue.ts +120 -0
  82. package/backup/recursive-type/src/data-structures/stack/index.ts +1 -0
  83. package/backup/recursive-type/src/data-structures/stack/stack.ts +98 -0
  84. package/backup/recursive-type/src/data-structures/tree/index.ts +1 -0
  85. package/backup/recursive-type/src/data-structures/tree/tree.ts +80 -0
  86. package/backup/recursive-type/src/data-structures/trie/index.ts +1 -0
  87. package/backup/recursive-type/src/data-structures/trie/trie.ts +227 -0
  88. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +5 -0
  89. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +8 -0
  90. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +10 -0
  91. package/backup/recursive-type/src/data-structures/types/bst.ts +6 -0
  92. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +8 -0
  93. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +1 -0
  94. package/backup/recursive-type/src/data-structures/types/heap.ts +5 -0
  95. package/backup/recursive-type/src/data-structures/types/index.ts +12 -0
  96. package/backup/recursive-type/src/data-structures/types/navigator.ts +13 -0
  97. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +9 -0
  98. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +1 -0
  99. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +1 -0
  100. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +1 -0
  101. package/backup/recursive-type/src/index.ts +1 -0
  102. package/backup/recursive-type/src/utils/index.ts +2 -0
  103. package/backup/recursive-type/src/utils/types/index.ts +1 -0
  104. package/backup/recursive-type/src/utils/types/utils.ts +6 -0
  105. package/backup/recursive-type/src/utils/utils.ts +78 -0
  106. package/dist/data-structures/binary-tree/avl-tree.d.ts +19 -25
  107. package/dist/data-structures/binary-tree/avl-tree.js +12 -20
  108. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +3 -1
  109. package/dist/data-structures/binary-tree/binary-indexed-tree.js +10 -0
  110. package/dist/data-structures/binary-tree/binary-tree.d.ts +135 -161
  111. package/dist/data-structures/binary-tree/binary-tree.js +192 -164
  112. package/dist/data-structures/binary-tree/bst.d.ts +21 -21
  113. package/dist/data-structures/binary-tree/bst.js +33 -36
  114. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
  115. package/dist/data-structures/binary-tree/rb-tree.js +68 -5
  116. package/dist/data-structures/binary-tree/segment-tree.d.ts +17 -39
  117. package/dist/data-structures/binary-tree/segment-tree.js +34 -47
  118. package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -8
  119. package/dist/data-structures/binary-tree/tree-multiset.js +7 -6
  120. package/dist/data-structures/graph/abstract-graph.d.ts +56 -71
  121. package/dist/data-structures/graph/abstract-graph.js +87 -92
  122. package/dist/data-structures/graph/directed-graph.d.ts +128 -105
  123. package/dist/data-structures/graph/directed-graph.js +161 -121
  124. package/dist/data-structures/graph/undirected-graph.d.ts +81 -62
  125. package/dist/data-structures/graph/undirected-graph.js +99 -78
  126. package/dist/data-structures/hash/coordinate-map.d.ts +1 -5
  127. package/dist/data-structures/hash/coordinate-map.js +3 -9
  128. package/dist/data-structures/hash/coordinate-set.d.ts +2 -6
  129. package/dist/data-structures/hash/coordinate-set.js +3 -9
  130. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  131. package/dist/data-structures/hash/hash-table.js +7 -0
  132. package/dist/data-structures/hash/pair.d.ts +2 -1
  133. package/dist/data-structures/hash/pair.js +7 -0
  134. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  135. package/dist/data-structures/hash/tree-map.js +7 -0
  136. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  137. package/dist/data-structures/hash/tree-set.js +7 -0
  138. package/dist/data-structures/heap/heap.d.ts +0 -14
  139. package/dist/data-structures/heap/heap.js +3 -27
  140. package/dist/data-structures/index.d.ts +1 -0
  141. package/dist/data-structures/index.js +1 -0
  142. package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
  143. package/dist/data-structures/interfaces/abstract-graph.js +2 -0
  144. package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
  145. package/dist/data-structures/interfaces/avl-tree.js +2 -0
  146. package/dist/data-structures/interfaces/binary-tree.d.ts +27 -0
  147. package/dist/data-structures/interfaces/binary-tree.js +2 -0
  148. package/dist/data-structures/interfaces/bst.d.ts +1 -0
  149. package/dist/data-structures/interfaces/bst.js +2 -0
  150. package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
  151. package/dist/data-structures/interfaces/directed-graph.js +2 -0
  152. package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
  153. package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
  154. package/dist/data-structures/interfaces/heap.d.ts +1 -0
  155. package/dist/data-structures/interfaces/heap.js +2 -0
  156. package/dist/data-structures/interfaces/index.d.ts +13 -0
  157. package/dist/data-structures/interfaces/index.js +29 -0
  158. package/dist/data-structures/interfaces/navigator.d.ts +1 -0
  159. package/dist/data-structures/interfaces/navigator.js +2 -0
  160. package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
  161. package/dist/data-structures/interfaces/priority-queue.js +2 -0
  162. package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
  163. package/dist/data-structures/interfaces/segment-tree.js +2 -0
  164. package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
  165. package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
  166. package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
  167. package/dist/data-structures/interfaces/tree-multiset.js +2 -0
  168. package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
  169. package/dist/data-structures/interfaces/undirected-graph.js +2 -0
  170. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -3
  171. package/dist/data-structures/linked-list/doubly-linked-list.js +12 -18
  172. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -2
  173. package/dist/data-structures/linked-list/singly-linked-list.js +12 -15
  174. package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
  175. package/dist/data-structures/priority-queue/priority-queue.js +4 -4
  176. package/dist/data-structures/queue/deque.d.ts +5 -5
  177. package/dist/data-structures/queue/deque.js +6 -6
  178. package/dist/data-structures/queue/queue.d.ts +1 -1
  179. package/dist/data-structures/stack/stack.d.ts +1 -1
  180. package/dist/data-structures/tree/tree.d.ts +12 -4
  181. package/dist/data-structures/tree/tree.js +44 -12
  182. package/dist/data-structures/trie/trie.d.ts +3 -3
  183. package/dist/data-structures/trie/trie.js +10 -10
  184. package/dist/data-structures/types/abstract-graph.d.ts +1 -20
  185. package/dist/data-structures/types/avl-tree.d.ts +5 -4
  186. package/dist/data-structures/types/binary-tree.d.ts +6 -5
  187. package/dist/data-structures/types/bst.d.ts +4 -3
  188. package/dist/data-structures/types/directed-graph.d.ts +5 -9
  189. package/dist/data-structures/types/directed-graph.js +7 -0
  190. package/dist/data-structures/types/doubly-linked-list.d.ts +1 -1
  191. package/dist/data-structures/types/heap.d.ts +2 -2
  192. package/dist/data-structures/types/index.d.ts +0 -1
  193. package/dist/data-structures/types/index.js +0 -1
  194. package/dist/data-structures/types/navigator.d.ts +2 -2
  195. package/dist/data-structures/types/priority-queue.d.ts +2 -2
  196. package/dist/data-structures/types/tree-multiset.d.ts +3 -4
  197. package/docs/assets/search.js +1 -1
  198. package/docs/classes/AVLTree.html +552 -405
  199. package/docs/classes/AVLTreeNode.html +107 -242
  200. package/docs/classes/AaTree.html +18 -13
  201. package/docs/classes/AbstractEdge.html +77 -68
  202. package/docs/classes/AbstractGraph.html +223 -115
  203. package/docs/classes/AbstractVertex.html +71 -45
  204. package/docs/classes/ArrayDeque.html +31 -26
  205. package/docs/classes/BST.html +543 -391
  206. package/docs/classes/BSTNode.html +107 -236
  207. package/docs/classes/BTree.html +18 -13
  208. package/docs/classes/BinaryIndexedTree.html +56 -21
  209. package/docs/classes/BinaryTree.html +564 -355
  210. package/docs/classes/BinaryTreeNode.html +146 -199
  211. package/docs/classes/Character.html +21 -16
  212. package/docs/classes/CoordinateMap.html +49 -52
  213. package/docs/classes/CoordinateSet.html +50 -53
  214. package/docs/classes/Deque.html +51 -68
  215. package/docs/classes/DirectedEdge.html +98 -103
  216. package/docs/classes/DirectedGraph.html +449 -210
  217. package/docs/classes/DirectedVertex.html +63 -52
  218. package/docs/classes/DoublyLinkedList.html +56 -71
  219. package/docs/classes/DoublyLinkedListNode.html +28 -23
  220. package/docs/classes/HashTable.html +155 -0
  221. package/docs/classes/Heap.html +33 -109
  222. package/docs/classes/HeapItem.html +25 -20
  223. package/docs/classes/Matrix2D.html +33 -28
  224. package/docs/classes/MatrixNTI2D.html +21 -16
  225. package/docs/classes/MaxHeap.html +33 -114
  226. package/docs/classes/MaxPriorityQueue.html +71 -61
  227. package/docs/classes/MinHeap.html +33 -114
  228. package/docs/classes/MinPriorityQueue.html +71 -61
  229. package/docs/classes/Navigator.html +28 -23
  230. package/docs/classes/ObjectDeque.html +66 -51
  231. package/docs/classes/{RBTree.html → Pair.html} +25 -20
  232. package/docs/classes/PriorityQueue.html +66 -56
  233. package/docs/classes/Queue.html +33 -28
  234. package/docs/classes/SegmentTree.html +129 -57
  235. package/docs/classes/SegmentTreeNode.html +62 -140
  236. package/docs/classes/SinglyLinkedList.html +53 -58
  237. package/docs/classes/SinglyLinkedListNode.html +25 -20
  238. package/docs/classes/SkipLinkedList.html +18 -13
  239. package/docs/classes/SplayTree.html +18 -13
  240. package/docs/classes/Stack.html +31 -26
  241. package/docs/classes/TreeMap.html +155 -0
  242. package/docs/classes/TreeMultiSet.html +541 -388
  243. package/docs/classes/TreeNode.html +125 -35
  244. package/docs/classes/TreeSet.html +155 -0
  245. package/docs/classes/Trie.html +30 -25
  246. package/docs/classes/TrieNode.html +33 -28
  247. package/docs/classes/TwoThreeTree.html +18 -13
  248. package/docs/classes/UndirectedEdge.html +87 -80
  249. package/docs/classes/UndirectedGraph.html +356 -178
  250. package/docs/classes/UndirectedVertex.html +63 -52
  251. package/docs/classes/Vector2D.html +45 -40
  252. package/docs/enums/CP.html +21 -16
  253. package/docs/enums/FamilyPosition.html +21 -16
  254. package/docs/enums/LoopType.html +20 -15
  255. package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +47 -44
  256. package/docs/index.html +203 -69
  257. package/docs/interfaces/{PriorityQueueOptions.html → IBinaryTree.html} +49 -40
  258. package/docs/interfaces/IBinaryTreeNode.html +383 -0
  259. package/docs/interfaces/IDirectedGraph.html +24 -19
  260. package/docs/interfaces/IGraph.html +122 -89
  261. package/docs/interfaces/{HeapOptions.html → IUNDirectedGraph.html} +26 -53
  262. package/docs/modules.html +33 -23
  263. package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +31 -22
  264. package/docs/types/BSTComparator.html +18 -13
  265. package/docs/types/BSTDeletedResult.html +23 -18
  266. package/docs/types/BinaryTreeDeleted.html +23 -18
  267. package/docs/types/BinaryTreeNodeId.html +18 -13
  268. package/docs/types/BinaryTreeNodePropertyName.html +18 -13
  269. package/docs/types/DFSOrderPattern.html +18 -13
  270. package/docs/types/DijkstraResult.html +18 -13
  271. package/docs/types/Direction.html +18 -13
  272. package/docs/types/{DoublyLinkedListGetBy.html → EdgeId.html} +22 -17
  273. package/docs/types/{TrlFn.html → HeapOptions.html} +33 -20
  274. package/docs/types/{TrlAsyncFn.html → NavigatorParams.html} +46 -20
  275. package/docs/types/NodeOrPropertyName.html +18 -13
  276. package/docs/types/PriorityQueueComparator.html +18 -13
  277. package/docs/types/PriorityQueueDFSOrderPattern.html +18 -13
  278. package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +32 -20
  279. package/docs/types/RecursiveAVLTreeNode.html +135 -0
  280. package/docs/types/RecursiveBSTNode.html +135 -0
  281. package/docs/types/RecursiveBinaryTreeNode.html +135 -0
  282. package/docs/types/ResultByProperty.html +21 -16
  283. package/docs/types/ResultsByProperty.html +21 -16
  284. package/docs/types/SegmentTreeNodeVal.html +18 -13
  285. package/docs/types/TopologicalStatus.html +18 -13
  286. package/docs/types/TreeMultiSetDeletedResult.html +23 -18
  287. package/docs/types/Turning.html +18 -13
  288. package/docs/types/VertexId.html +18 -13
  289. package/notes/note.md +12 -1
  290. package/package.json +11 -3
  291. package/tsconfig.json +2 -2
  292. package/docs/interfaces/NavigatorParams.html +0 -197
  293. package/docs/types/Thunk.html +0 -133
@@ -33,22 +33,23 @@ var TreeMultiSet = /** @class */ (function (_super) {
33
33
  * The function creates a new BSTNode with the given id, value, and count.
34
34
  * @param {BinaryTreeNodeId} id - The id parameter is the unique identifier for the binary tree node. It is used to
35
35
  * distinguish one node from another in the tree.
36
- * @param {T} val - The `val` parameter represents the value that will be stored in the binary search tree node.
36
+ * @param {N} val - The `val` parameter represents the value that will be stored in the binary search tree node.
37
37
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
38
38
  * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
39
39
  * @returns A new instance of the BSTNode class with the specified id, value, and count (if provided).
40
40
  */
41
- TreeMultiSet.prototype.createNode = function (id, val, count) {
42
- return new bst_1.BSTNode(id, val, count);
41
+ TreeMultiSet.prototype._createNode = function (id, val, count) {
42
+ var node = new bst_1.BSTNode(id, val, count);
43
+ return node;
43
44
  };
44
45
  /**
45
46
  * The function overrides the add method of the BinarySearchTree class in TypeScript.
46
47
  * @param {BinaryTreeNodeId} id - The `id` parameter is the identifier of the binary tree node that you want to add.
47
- * @param {T | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
48
- * can be of type `T` (the generic type) or `null`.
48
+ * @param {N | null} val - The `val` parameter represents the value that you want to add to the binary search tree. It
49
+ * can be of type `N` (the generic type) or `null`.
49
50
  * @param {number} [count] - The `count` parameter is an optional parameter of type `number`. It represents the number
50
51
  * of times the value should be added to the binary search tree. If not provided, the default value is `undefined`.
51
- * @returns The `add` method is returning a `BSTNode<T>` object or `null`.
52
+ * @returns The `add` method is returning a `BSTNode<N>` object or `null`.
52
53
  */
53
54
  TreeMultiSet.prototype.add = function (id, val, count) {
54
55
  return _super.prototype.add.call(this, id, val, count);
@@ -1,57 +1,50 @@
1
- import type { DijkstraResult, IGraph, VertexId } from '../types';
2
- export declare class AbstractVertex {
3
- constructor(id: VertexId);
4
- protected _id: VertexId;
1
+ import type { DijkstraResult, VertexId } from '../types';
2
+ import { IGraph } from '../interfaces';
3
+ export declare abstract class AbstractVertex<T = number> {
4
+ protected constructor(id: VertexId, val?: T);
5
+ private _id;
5
6
  get id(): VertexId;
6
7
  set id(v: VertexId);
7
- /**
8
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
9
- */
10
- getId(): VertexId;
8
+ private _val;
9
+ get val(): T | undefined;
10
+ set val(value: T | undefined);
11
11
  }
12
- export declare abstract class AbstractEdge {
13
- static DEFAULT_EDGE_WEIGHT: number;
14
- /**
15
- * The function is a protected constructor that initializes the weight and generates a unique hash code for an edge.
16
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
17
- * no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
18
- */
19
- protected constructor(weight?: number);
12
+ export declare abstract class AbstractEdge<T = number> {
13
+ protected constructor(weight?: number, val?: T);
14
+ private _val;
15
+ get val(): T | undefined;
16
+ set val(value: T | undefined);
20
17
  private _weight;
21
18
  get weight(): number;
22
19
  set weight(v: number);
23
- private _hashCode;
20
+ protected _hashCode: string;
24
21
  get hashCode(): string;
25
- set hashCode(v: string);
22
+ protected _setHashCode(v: string): void;
23
+ }
24
+ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E extends AbstractEdge<any>> implements IGraph<V, E> {
25
+ private _vertices;
26
+ get vertices(): Map<VertexId, V>;
26
27
  /**
27
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
28
+ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
29
+ * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
30
+ * @param id
31
+ * @param val
28
32
  */
29
- getWeight(): number;
33
+ abstract _createVertex(id: VertexId, val?: V): V;
30
34
  /**
31
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
35
+ * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
36
+ * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
37
+ * @param srcOrV1
38
+ * @param destOrV2
39
+ * @param weight
40
+ * @param val
32
41
  */
33
- getHashCode(): string;
34
- }
35
- export declare abstract class AbstractGraph<V extends AbstractVertex, E extends AbstractEdge> implements IGraph<V, E> {
36
- protected _vertices: Map<VertexId, V>;
42
+ abstract _createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
37
43
  abstract removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
38
44
  abstract removeEdge(edge: E): E | null;
39
- /**
40
- * The function `getVertex` returns the vertex object associated with a given vertex ID or vertex object, or null if it
41
- * does not exist.
42
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
43
- * @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
44
- * If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
45
- */
46
- getVertex(vertexOrId: VertexId | V): V | null;
47
- /**
48
- * The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
49
- * a `VertexId`.
50
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
51
- * (`VertexId`).
52
- * @returns the id of the vertex.
53
- */
54
- getVertexId(vertexOrId: V | VertexId): VertexId;
45
+ _getVertex(vertexOrId: VertexId | V): V | null;
46
+ getVertex(vertexId: VertexId): V | null;
47
+ _getVertexId(vertexOrId: V | VertexId): VertexId;
55
48
  /**
56
49
  * The function checks if a vertex exists in a graph.
57
50
  * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
@@ -59,18 +52,8 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
59
52
  * @returns The method `hasVertex` returns a boolean value.
60
53
  */
61
54
  hasVertex(vertexOrId: V | VertexId): boolean;
62
- /**
63
- * The function `vertexSet()` returns a map of vertices.
64
- * @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
65
- */
66
- vertexSet(): Map<VertexId, V>;
67
- abstract getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
68
- /**
69
- * The addVertex function adds a new vertex to a graph if it does not already exist.
70
- * @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
71
- * @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
72
- * false. Otherwise, it will add the newVertex to the graph and return true.
73
- */
55
+ abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
56
+ createAddVertex(id: VertexId, val?: V['val']): boolean;
74
57
  addVertex(newVertex: V): boolean;
75
58
  /**
76
59
  * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
@@ -100,6 +83,7 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
100
83
  * vertices `v1` and `v2`, and `false` otherwise.
101
84
  */
102
85
  hasEdge(v1: VertexId | V, v2: VertexId | V): boolean;
86
+ createAddEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E['val']): boolean;
103
87
  abstract addEdge(edge: E): boolean;
104
88
  /**
105
89
  * The function sets the weight of an edge between two vertices in a graph.
@@ -176,15 +160,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
176
160
  * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
177
161
  */
178
162
  dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
179
- /**
180
- * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
181
- * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
182
- * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
183
- */
184
- /**
185
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
186
- * 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.
187
- */
188
163
  /**
189
164
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
190
165
  * 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.
@@ -204,13 +179,16 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
204
179
  * @returns The function `dijkstra` returns an object of type `DijkstraResult<V>`.
205
180
  */
206
181
  dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
207
- abstract getEndsOfEdge(edge: E): [V, V] | null;
208
182
  /**
209
- * BellmanFord time:O(VE) space:O(V)
210
- * one to rest pairs
211
- * 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 edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
212
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
183
+ * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
184
+ * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
185
+ * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
213
186
  */
187
+ /**
188
+ * Dijkstra algorithm time: O(logVE) space: O(V + E)
189
+ * 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.
190
+ */
191
+ abstract getEndsOfEdge(edge: E): [V, V] | null;
214
192
  /**
215
193
  * BellmanFord time:O(VE) space:O(V)
216
194
  * one to rest pairs
@@ -236,9 +214,10 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
236
214
  minPath: V[];
237
215
  };
238
216
  /**
239
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
240
- * all pairs
241
- * 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 edges, and it can simultaneously compute shortest paths between any two nodes.
217
+ * BellmanFord time:O(VE) space:O(V)
218
+ * one to rest pairs
219
+ * 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 edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
220
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
242
221
  */
243
222
  /**
244
223
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
@@ -255,7 +234,11 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
255
234
  costs: number[][];
256
235
  predecessor: (V | null)[][];
257
236
  };
258
- /**--- start find cycles --- */
237
+ /**
238
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
239
+ * all pairs
240
+ * 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 edges, and it can simultaneously compute shortest paths between any two nodes.
241
+ */
259
242
  /**
260
243
  * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
261
244
  * Tarjan can find cycles in directed or undirected graph
@@ -285,4 +268,6 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
285
268
  SCCs: Map<number, V[]>;
286
269
  cycles: Map<number, V[]>;
287
270
  };
271
+ /**--- start find cycles --- */
272
+ protected _setVertices(value: Map<VertexId, V>): void;
288
273
  }
@@ -47,8 +47,9 @@ exports.AbstractGraph = exports.AbstractEdge = exports.AbstractVertex = void 0;
47
47
  var utils_1 = require("../../utils");
48
48
  var priority_queue_1 = require("../priority-queue");
49
49
  var AbstractVertex = /** @class */ (function () {
50
- function AbstractVertex(id) {
50
+ function AbstractVertex(id, val) {
51
51
  this._id = id;
52
+ this._val = val;
52
53
  }
53
54
  Object.defineProperty(AbstractVertex.prototype, "id", {
54
55
  get: function () {
@@ -60,27 +61,35 @@ var AbstractVertex = /** @class */ (function () {
60
61
  enumerable: false,
61
62
  configurable: true
62
63
  });
63
- /**
64
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
65
- */
66
- AbstractVertex.prototype.getId = function () {
67
- return this._id;
68
- };
64
+ Object.defineProperty(AbstractVertex.prototype, "val", {
65
+ get: function () {
66
+ return this._val;
67
+ },
68
+ set: function (value) {
69
+ this._val = value;
70
+ },
71
+ enumerable: false,
72
+ configurable: true
73
+ });
69
74
  return AbstractVertex;
70
75
  }());
71
76
  exports.AbstractVertex = AbstractVertex;
72
77
  var AbstractEdge = /** @class */ (function () {
73
- /**
74
- * The function is a protected constructor that initializes the weight and generates a unique hash code for an edge.
75
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
76
- * no weight is provided, it will default to the value of `AbstractEdge.DEFAULT_EDGE_WEIGHT`.
77
- */
78
- function AbstractEdge(weight) {
79
- if (weight === undefined)
80
- weight = AbstractEdge.DEFAULT_EDGE_WEIGHT;
81
- this._weight = weight;
78
+ function AbstractEdge(weight, val) {
79
+ this._weight = weight !== undefined ? weight : 1;
80
+ this._val = val;
82
81
  this._hashCode = (0, utils_1.uuidV4)();
83
82
  }
83
+ Object.defineProperty(AbstractEdge.prototype, "val", {
84
+ get: function () {
85
+ return this._val;
86
+ },
87
+ set: function (value) {
88
+ this._val = value;
89
+ },
90
+ enumerable: false,
91
+ configurable: true
92
+ });
84
93
  Object.defineProperty(AbstractEdge.prototype, "weight", {
85
94
  get: function () {
86
95
  return this._weight;
@@ -95,25 +104,21 @@ var AbstractEdge = /** @class */ (function () {
95
104
  get: function () {
96
105
  return this._hashCode;
97
106
  },
98
- set: function (v) {
99
- this._hashCode = v;
100
- },
101
107
  enumerable: false,
102
108
  configurable: true
103
109
  });
104
- /**
105
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
106
- */
107
- AbstractEdge.prototype.getWeight = function () {
108
- return this._weight;
110
+ // /**
111
+ // * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
112
+ // * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
113
+ // * @param srcOrV1
114
+ // * @param destOrV2
115
+ // * @param weight
116
+ // * @param val
117
+ // */
118
+ // abstract _createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
119
+ AbstractEdge.prototype._setHashCode = function (v) {
120
+ this._hashCode = v;
109
121
  };
110
- /**
111
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
112
- */
113
- AbstractEdge.prototype.getHashCode = function () {
114
- return this._hashCode;
115
- };
116
- AbstractEdge.DEFAULT_EDGE_WEIGHT = 1;
117
122
  return AbstractEdge;
118
123
  }());
119
124
  exports.AbstractEdge = AbstractEdge;
@@ -125,25 +130,21 @@ var AbstractGraph = /** @class */ (function () {
125
130
  /**--- end find cycles --- */
126
131
  // Minimum Spanning Tree
127
132
  }
128
- /**
129
- * The function `getVertex` returns the vertex object associated with a given vertex ID or vertex object, or null if it
130
- * does not exist.
131
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
132
- * @returns The function `getVertex` returns the vertex object (`V`) corresponding to the given `vertexOrId` parameter.
133
- * If the vertex is found in the `_vertices` map, it is returned. Otherwise, `null` is returned.
134
- */
135
- AbstractGraph.prototype.getVertex = function (vertexOrId) {
136
- var vertexId = this.getVertexId(vertexOrId);
133
+ Object.defineProperty(AbstractGraph.prototype, "vertices", {
134
+ get: function () {
135
+ return this._vertices;
136
+ },
137
+ enumerable: false,
138
+ configurable: true
139
+ });
140
+ AbstractGraph.prototype._getVertex = function (vertexOrId) {
141
+ var vertexId = this._getVertexId(vertexOrId);
137
142
  return this._vertices.get(vertexId) || null;
138
143
  };
139
- /**
140
- * The function `getVertexId` returns the id of a vertex, whether it is passed as an instance of `AbstractVertex` or as
141
- * a `VertexId`.
142
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
143
- * (`VertexId`).
144
- * @returns the id of the vertex.
145
- */
146
- AbstractGraph.prototype.getVertexId = function (vertexOrId) {
144
+ AbstractGraph.prototype.getVertex = function (vertexId) {
145
+ return this._vertices.get(vertexId) || null;
146
+ };
147
+ AbstractGraph.prototype._getVertexId = function (vertexOrId) {
147
148
  return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
148
149
  };
149
150
  /**
@@ -153,24 +154,16 @@ var AbstractGraph = /** @class */ (function () {
153
154
  * @returns The method `hasVertex` returns a boolean value.
154
155
  */
155
156
  AbstractGraph.prototype.hasVertex = function (vertexOrId) {
156
- return this._vertices.has(this.getVertexId(vertexOrId));
157
+ return this._vertices.has(this._getVertexId(vertexOrId));
157
158
  };
158
- /**
159
- * The function `vertexSet()` returns a map of vertices.
160
- * @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
161
- */
162
- AbstractGraph.prototype.vertexSet = function () {
163
- return this._vertices;
159
+ AbstractGraph.prototype.createAddVertex = function (id, val) {
160
+ var newVertex = this._createVertex(id, val);
161
+ return this.addVertex(newVertex);
164
162
  };
165
- /**
166
- * The addVertex function adds a new vertex to a graph if it does not already exist.
167
- * @param {V} newVertex - The parameter "newVertex" is of type V, which represents a vertex in a graph.
168
- * @returns The method is returning a boolean value. If the newVertex is already contained in the graph, it will return
169
- * false. Otherwise, it will add the newVertex to the graph and return true.
170
- */
171
163
  AbstractGraph.prototype.addVertex = function (newVertex) {
172
164
  if (this.hasVertex(newVertex)) {
173
165
  return false;
166
+ // throw (new Error('Duplicated vertex id is not allowed'));
174
167
  }
175
168
  this._vertices.set(newVertex.id, newVertex);
176
169
  return true;
@@ -182,7 +175,7 @@ var AbstractGraph = /** @class */ (function () {
182
175
  * @returns The method `removeVertex` returns a boolean value.
183
176
  */
184
177
  AbstractGraph.prototype.removeVertex = function (vertexOrId) {
185
- var vertexId = this.getVertexId(vertexOrId);
178
+ var vertexId = this._getVertexId(vertexOrId);
186
179
  return this._vertices.delete(vertexId);
187
180
  };
188
181
  /**
@@ -223,6 +216,14 @@ var AbstractGraph = /** @class */ (function () {
223
216
  var edge = this.getEdge(v1, v2);
224
217
  return !!edge;
225
218
  };
219
+ AbstractGraph.prototype.createAddEdge = function (src, dest, weight, val) {
220
+ if (src instanceof AbstractVertex)
221
+ src = src.id;
222
+ if (dest instanceof AbstractVertex)
223
+ dest = dest.id;
224
+ var newEdge = this._createEdge(src, dest, weight, val);
225
+ return this.addEdge(newEdge);
226
+ };
226
227
  /**
227
228
  * The function sets the weight of an edge between two vertices in a graph.
228
229
  * @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
@@ -256,8 +257,8 @@ var AbstractGraph = /** @class */ (function () {
256
257
  AbstractGraph.prototype.getAllPathsBetween = function (v1, v2) {
257
258
  var _this = this;
258
259
  var paths = [];
259
- var vertex1 = this.getVertex(v1);
260
- var vertex2 = this.getVertex(v2);
260
+ var vertex1 = this._getVertex(v1);
261
+ var vertex2 = this._getVertex(v2);
261
262
  if (!(vertex1 && vertex2)) {
262
263
  return [];
263
264
  }
@@ -344,8 +345,8 @@ var AbstractGraph = /** @class */ (function () {
344
345
  }
345
346
  else {
346
347
  // BFS
347
- var vertex2 = this.getVertex(v2);
348
- var vertex1 = this.getVertex(v1);
348
+ var vertex2 = this._getVertex(v2);
349
+ var vertex1 = this._getVertex(v1);
349
350
  if (!(vertex1 && vertex2)) {
350
351
  return null;
351
352
  }
@@ -430,8 +431,8 @@ var AbstractGraph = /** @class */ (function () {
430
431
  else {
431
432
  // BFS
432
433
  var minPath_1 = [];
433
- var vertex1_1 = this.getVertex(v1);
434
- var vertex2 = this.getVertex(v2);
434
+ var vertex1_1 = this._getVertex(v1);
435
+ var vertex2 = this._getVertex(v2);
435
436
  if (!(vertex1_1 && vertex2)) {
436
437
  return [];
437
438
  }
@@ -502,8 +503,8 @@ var AbstractGraph = /** @class */ (function () {
502
503
  var distMap = new Map();
503
504
  var seen = new Set();
504
505
  var preMap = new Map(); // predecessor
505
- var srcVertex = this.getVertex(src);
506
- var destVertex = dest ? this.getVertex(dest) : null;
506
+ var srcVertex = this._getVertex(src);
507
+ var destVertex = dest ? this._getVertex(dest) : null;
507
508
  if (!srcVertex) {
508
509
  return null;
509
510
  }
@@ -630,15 +631,6 @@ var AbstractGraph = /** @class */ (function () {
630
631
  genPaths && getPaths(minDest);
631
632
  return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
632
633
  };
633
- /**
634
- * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
635
- * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
636
- * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
637
- */
638
- /**
639
- * Dijkstra algorithm time: O(logVE) space: O(V + E)
640
- * 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.
641
- */
642
634
  /**
643
635
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
644
636
  * 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.
@@ -674,8 +666,8 @@ var AbstractGraph = /** @class */ (function () {
674
666
  var distMap = new Map();
675
667
  var seen = new Set();
676
668
  var preMap = new Map(); // predecessor
677
- var srcVertex = this.getVertex(src);
678
- var destVertex = dest ? this.getVertex(dest) : null;
669
+ var srcVertex = this._getVertex(src);
670
+ var destVertex = dest ? this._getVertex(dest) : null;
679
671
  if (!srcVertex) {
680
672
  return null;
681
673
  }
@@ -787,12 +779,6 @@ var AbstractGraph = /** @class */ (function () {
787
779
  }
788
780
  return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
789
781
  };
790
- /**
791
- * BellmanFord time:O(VE) space:O(V)
792
- * one to rest pairs
793
- * 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 edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
794
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
795
- */
796
782
  /**
797
783
  * BellmanFord time:O(VE) space:O(V)
798
784
  * one to rest pairs
@@ -815,7 +801,7 @@ var AbstractGraph = /** @class */ (function () {
815
801
  getMin = false;
816
802
  if (genPath === undefined)
817
803
  genPath = false;
818
- var srcVertex = this.getVertex(src);
804
+ var srcVertex = this._getVertex(src);
819
805
  var paths = [];
820
806
  var distMap = new Map();
821
807
  var preMap = new Map(); // predecessor
@@ -906,9 +892,10 @@ var AbstractGraph = /** @class */ (function () {
906
892
  return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
907
893
  };
908
894
  /**
909
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
910
- * all pairs
911
- * 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 edges, and it can simultaneously compute shortest paths between any two nodes.
895
+ * BellmanFord time:O(VE) space:O(V)
896
+ * one to rest pairs
897
+ * 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 edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
898
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
912
899
  */
913
900
  /**
914
901
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
@@ -952,7 +939,11 @@ var AbstractGraph = /** @class */ (function () {
952
939
  }
953
940
  return { costs: costs, predecessor: predecessor };
954
941
  };
955
- /**--- start find cycles --- */
942
+ /**
943
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
944
+ * all pairs
945
+ * 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 edges, and it can simultaneously compute shortest paths between any two nodes.
946
+ */
956
947
  /**
957
948
  * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
958
949
  * Tarjan can find cycles in directed or undirected graph
@@ -1080,6 +1071,10 @@ var AbstractGraph = /** @class */ (function () {
1080
1071
  }
1081
1072
  return { dfnMap: dfnMap, lowMap: lowMap, bridges: bridges, articulationPoints: articulationPoints, SCCs: SCCs, cycles: cycles };
1082
1073
  };
1074
+ /**--- start find cycles --- */
1075
+ AbstractGraph.prototype._setVertices = function (value) {
1076
+ this._vertices = value;
1077
+ };
1083
1078
  return AbstractGraph;
1084
1079
  }());
1085
1080
  exports.AbstractGraph = AbstractGraph;