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
@@ -1,175 +1,198 @@
1
1
  import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
2
- import type { IDirectedGraph, VertexId } from '../types';
3
- export declare class DirectedVertex extends AbstractVertex {
2
+ import type { VertexId } from '../types';
3
+ import { IDirectedGraph } from '../interfaces';
4
+ export declare class DirectedVertex<T = number> extends AbstractVertex<T> {
4
5
  /**
5
- * The constructor function initializes an object with a given id.
6
- * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
7
- * vertex within a graph or network.
6
+ * The constructor function initializes a vertex with an optional value.
7
+ * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
8
+ * typically a unique identifier for each vertex in a graph.
9
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to specify the value
10
+ * associated with the vertex.
8
11
  */
9
- constructor(id: VertexId);
12
+ constructor(id: VertexId, val?: T);
10
13
  }
11
- export declare class DirectedEdge extends AbstractEdge {
14
+ export declare class DirectedEdge<T = number> extends AbstractEdge<T> {
12
15
  /**
13
- * The constructor function initializes the source and destination vertices of an edge, with an optional weight.
16
+ * The constructor function initializes the source and destination vertices of an edge, along with an optional weight
17
+ * and value.
14
18
  * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
15
19
  * a graph.
16
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex. It represents the vertex
17
- * to which an edge is directed.
18
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
19
- * between two vertices.
20
- */
21
- constructor(src: VertexId, dest: VertexId, weight?: number);
20
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
21
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
22
+ * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
23
+ * If the weight is not provided, it will default to `undefined`.
24
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
25
+ * the edge.
26
+ */
27
+ constructor(src: VertexId, dest: VertexId, weight?: number, val?: T);
22
28
  private _src;
23
29
  get src(): VertexId;
24
30
  set src(v: VertexId);
25
31
  private _dest;
26
32
  get dest(): VertexId;
27
33
  set dest(v: VertexId);
28
- /**
29
- * 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.
30
- */
31
- getSrc(): VertexId;
32
- /**
33
- * 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.
34
- */
35
- getDest(): VertexId;
36
34
  }
37
- export declare class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
38
- protected _outEdgeMap: Map<V, E[]>;
39
- protected _inEdgeMap: Map<V, E[]>;
40
- constructor();
41
- /**
42
- * The function `getEdge` returns the first edge between two vertices, given their source and destination.
43
- * @param {V | null | VertexId} srcOrId - The `srcOrId` parameter can be either a vertex object (`V`), a vertex ID
44
- * (`VertexId`), or `null`. It represents the source vertex of the edge.
45
- * @param {V | null | VertexId} destOrId - The `destOrId` parameter is either a vertex object (`V`), a vertex ID
46
- * (`VertexId`), or `null`. It represents the destination vertex of the edge.
47
- * @returns an edge (E) or null.
35
+ export declare class DirectedGraph<V extends DirectedVertex<any>, E extends DirectedEdge<any>> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
36
+ private readonly _vertexConstructor;
37
+ private readonly _edgeConstructor;
38
+ constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E);
39
+ private _outEdgeMap;
40
+ get outEdgeMap(): Map<V, E[]>;
41
+ private _inEdgeMap;
42
+ get inEdgeMap(): Map<V, E[]>;
43
+ /**
44
+ * 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.
45
+ * 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.
46
+ * @param id
47
+ * @param val
48
+ */
49
+ _createVertex(id: VertexId, val?: V['val']): V;
50
+ /**
51
+ * 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.
52
+ * 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.
53
+ * @param src
54
+ * @param dest
55
+ * @param weight
56
+ * @param val
57
+ */
58
+ _createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
59
+ /**
60
+ * The function `getEdge` returns the directed edge between two vertices, given their source and destination.
61
+ * @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
62
+ * DirectedVertex object or a VertexId.
63
+ * @param {V | null | VertexId} destOrId - The `destOrId` parameter is the destination vertex or its
64
+ * ID. It can be either a `DirectedVertex` object or a `VertexId` value.
65
+ * @returns a E object or null.
48
66
  */
49
67
  getEdge(srcOrId: V | null | VertexId, destOrId: V | null | VertexId): E | null;
50
68
  /**
51
- * The `addEdge` function adds an edge to a graph if the source and destination vertices exist.
52
- * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in the graph. It contains
53
- * information about the source vertex (`src`) and the destination vertex (`dest`) of the edge.
54
- * @returns The `addEdge` function returns a boolean value. It returns `true` if the edge was successfully added to the
55
- * graph, and `false` if either the source or destination vertices of the edge are not present in the graph.
69
+ * The `addEdge` function adds a directed edge to a graph if the source and destination vertices exist.
70
+ * @param edge - The parameter `edge` is of type `E`, which represents a directed edge in a graph. It
71
+ * contains two properties:
72
+ * @returns The method `addEdge` returns a boolean value. It returns `true` if the edge was successfully added to the
73
+ * graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
56
74
  */
57
75
  addEdge(edge: E): boolean;
58
76
  /**
59
- * The function removes an edge between two vertices in a directed graph and returns the removed edge.
60
- * @param {V | VertexId} srcOrId - The source vertex or its ID.
61
- * @param {V | VertexId} destOrId - The `destOrId` parameter in the `removeEdgeBetween` function represents the
62
- * destination vertex of the edge that needs to be removed. It can be either a vertex object (`V`) or a vertex ID
63
- * (`VertexId`).
64
- * @returns The function `removeEdgeBetween` returns the removed edge (`E`) if the edge between the source and
65
- * destination vertices is successfully removed. If either the source or destination vertex is not found, or if the
66
- * edge does not exist, it returns `null`.
77
+ * The `removeEdgeBetween` function removes an edge between two vertices in a directed graph and returns the removed
78
+ * edge, or null if the edge was not found.
79
+ * @param {V | VertexId} srcOrId - The `srcOrId` parameter represents either a `V`
80
+ * object or a `VertexId` value. It is used to specify the source vertex of the edge that you want to remove.
81
+ * @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex of the
82
+ * edge that you want to remove. It can be either a `V` object or a `VertexId` value.
83
+ * @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
84
+ * the edge does not exist.
67
85
  */
68
86
  removeEdgeBetween(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
69
87
  /**
70
- * The removeEdge function removes an edge from a graph and returns the removed edge, or null if the edge was not
71
- * found.
72
- * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
73
- * and `dest`, which represent the source and destination vertices of the edge, respectively.
74
- * @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
88
+ * The `removeEdge` function removes a directed edge from a graph and returns the removed edge, or null if the edge was
89
+ * not found.
90
+ * @param edge - The `edge` parameter is an object of type `E`, which represents a directed edge in a
91
+ * graph. It has two properties:
92
+ * @returns The function `removeEdge` returns a `E` object if an edge is successfully removed, or `null`
93
+ * if no edge is removed.
75
94
  */
76
95
  removeEdge(edge: E): E | null;
77
96
  /**
78
97
  * The function removeAllEdges removes all edges between two vertices.
79
- * @param {VertexId | V} src - The `src` parameter represents the source vertex from which the edges will be removed.
80
- * It can be either a `VertexId` or a `V` type, which represents the identifier or object of the vertex.
81
- * @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It can be either a
82
- * `VertexId` or a vertex object `V`.
83
- * @returns An empty array is being returned.
98
+ * @param {VertexId | V} src - The `src` parameter can be either a `VertexId` or a `V`.
99
+ * @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It
100
+ * can be either a `VertexId` or a `V`.
101
+ * @returns An empty array of DirectedEdge objects is being returned.
84
102
  */
85
103
  removeAllEdges(src: VertexId | V, dest: VertexId | V): E[];
86
104
  /**
87
- * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
88
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
89
- * (`VertexId`).
90
- * @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
105
+ * The function returns an array of incoming edges of a given vertex or vertex ID.
106
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
107
+ * object or a `VertexId`.
108
+ * @returns The method `incomingEdgesOf` returns an array of `E` objects.
91
109
  */
92
110
  incomingEdgesOf(vertexOrId: V | VertexId): E[];
93
111
  /**
94
- * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
95
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
96
- * (`VertexId`).
97
- * @returns The method `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
112
+ * The function `outgoingEdgesOf` returns an array of outgoing directed edges from a given vertex or vertex ID.
113
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
114
+ * object or a `VertexId`.
115
+ * @returns The method `outgoingEdgesOf` returns an array of `E` objects.
98
116
  */
99
117
  outgoingEdgesOf(vertexOrId: V | VertexId): E[];
100
118
  /**
101
- * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
102
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
103
- * @returns the sum of the out-degree and in-degree of the specified vertex or vertex ID.
119
+ * The function "degreeOf" returns the total degree of a vertex in a directed graph, which is the sum of its out-degree
120
+ * and in-degree.
121
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
122
+ * `V`.
123
+ * @returns The sum of the out-degree and in-degree of the given vertex or vertex ID.
104
124
  */
105
125
  degreeOf(vertexOrId: VertexId | V): number;
106
126
  /**
107
- * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
108
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
127
+ * The function "inDegreeOf" returns the number of incoming edges for a given vertex or vertex ID in a directed graph.
128
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
129
+ * `V`.
109
130
  * @returns The number of incoming edges of the specified vertex or vertex ID.
110
131
  */
111
132
  inDegreeOf(vertexOrId: VertexId | V): number;
112
133
  /**
113
- * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
114
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
134
+ * The function "outDegreeOf" returns the number of outgoing edges from a given vertex.
135
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
136
+ * `V`.
115
137
  * @returns The number of outgoing edges from the specified vertex or vertex ID.
116
138
  */
117
139
  outDegreeOf(vertexOrId: VertexId | V): number;
118
140
  /**
119
- * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
120
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
121
- * @returns The function `edgesOf` returns an array of edges.
141
+ * The function "edgesOf" returns an array of both outgoing and incoming directed edges of a given vertex or vertex ID.
142
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
143
+ * `V`.
144
+ * @returns an array of directed edges.
122
145
  */
123
146
  edgesOf(vertexOrId: VertexId | V): E[];
124
147
  /**
125
- * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
126
- * @param {E} e - E - an edge object
127
- * @returns the source vertex of the given edge, or null if the edge does not exist.
148
+ * The function "getEdgeSrc" returns the source vertex of a directed edge, or null if the edge does not exist.
149
+ * @param e - A directed edge object of type E.
150
+ * @returns either a DirectedVertex object or null.
128
151
  */
129
152
  getEdgeSrc(e: E): V | null;
130
153
  /**
131
- * The function "getEdgeDest" returns the vertex associated with the destination of an edge.
132
- * @param {E} e - The parameter `e` is of type `E`, which represents an edge in a graph.
133
- * @returns either a vertex object (of type V) or null.
154
+ * The function "getEdgeDest" returns the destination vertex of a directed edge.
155
+ * @param e - E - This is an object representing a directed edge in a graph. It contains information
156
+ * about the source vertex, destination vertex, and any associated data.
157
+ * @returns either a DirectedVertex object or null.
134
158
  */
135
159
  getEdgeDest(e: E): V | null;
136
160
  /**
137
- * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
138
- * @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
139
- * find the destinations. It can be either a `V` object, a `VertexId` (which is a unique identifier for a vertex), or
140
- * `null` if we want to find destinations from all vertices.
141
- * @returns an array of vertices (V[]).
161
+ * The function `getDestinations` returns an array of directed vertices that are the destinations of outgoing edges
162
+ * from a given vertex.
163
+ * @param {V | VertexId | null} vertex - The `vertex` parameter can be one of the following:
164
+ * @returns an array of DirectedVertex objects.
142
165
  */
143
166
  getDestinations(vertex: V | VertexId | null): V[];
144
- /**--- start find cycles --- */
145
167
  /**
146
- * when stored with adjacency list time: O(V+E)
147
- * when stored with adjacency matrix time: O(V^2)
148
- * The `topologicalSort` function performs a topological sort on a graph and returns the sorted vertices in reverse
149
- * order, or null if the graph contains a cycle.
150
- * @returns The `topologicalSort()` function returns an array of vertices (`V[]`) in topological order if there is no
151
- * cycle in the graph. If there is a cycle, it returns `null`.
168
+ * The `topologicalSort` function performs a topological sort on a directed graph and returns the sorted vertices in
169
+ * reverse order, or null if the graph contains a cycle.
170
+ * @returns The function `topologicalSort()` returns an array of `V` or `VertexId` objects in
171
+ * topological order, or `null` if there is a cycle in the graph.
152
172
  */
153
- topologicalSort(): V[] | null;
154
- /**--- end find cycles --- */
173
+ topologicalSort(): Array<V | VertexId> | null;
155
174
  /**
156
- * The `edgeSet` function returns an array of all the edges in the graph.
157
- * @returns The `edgeSet()` method returns an array of edges (`E[]`).
175
+ * The `edgeSet` function returns an array of all directed edges in the graph.
176
+ * @returns The `edgeSet()` method returns an array of `E` objects.
158
177
  */
159
178
  edgeSet(): E[];
179
+ /**--- start find cycles --- */
160
180
  /**
161
- * The function `getNeighbors` returns an array of neighboring vertices for a given vertex or vertex ID.
162
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
163
- * (`VertexId`).
164
- * @returns an array of vertices (V[]).
181
+ * The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a directed graph.
182
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
183
+ * object or a `VertexId`.
184
+ * @returns an array of DirectedVertex objects.
165
185
  */
166
186
  getNeighbors(vertexOrId: V | VertexId): V[];
187
+ /**--- end find cycles --- */
167
188
  /**
168
- * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
169
- * otherwise it returns null.
170
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
171
- * @returns an array containing two vertices [V, V] if the edge is found in the graph. If the edge is not found, it
172
- * returns null.
189
+ * The function "getEndsOfEdge" returns the source and destination vertices of a directed edge if it exists in the
190
+ * graph, otherwise it returns null.
191
+ * @param edge - A directed edge object with a generic type E.
192
+ * @returns an array containing the starting and ending vertices of the given directed edge, or null if the edge does
193
+ * not exist in the graph.
173
194
  */
174
195
  getEndsOfEdge(edge: E): [V, V] | null;
196
+ protected _setOutEdgeMap(value: Map<V, E[]>): void;
197
+ protected _setInEdgeMap(value: Map<V, E[]>): void;
175
198
  }