data-structure-typed 1.18.7 → 1.19.0

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 (269) hide show
  1. package/README.md +208 -419
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +198 -167
  3. package/dist/data-structures/binary-tree/abstract-binary-tree.js +413 -398
  4. package/dist/data-structures/binary-tree/avl-tree.d.ts +24 -16
  5. package/dist/data-structures/binary-tree/avl-tree.js +23 -17
  6. package/dist/data-structures/binary-tree/binary-tree.d.ts +12 -26
  7. package/dist/data-structures/binary-tree/binary-tree.js +12 -27
  8. package/dist/data-structures/binary-tree/bst.d.ts +66 -90
  9. package/dist/data-structures/binary-tree/bst.js +85 -163
  10. package/dist/data-structures/binary-tree/rb-tree.d.ts +6 -17
  11. package/dist/data-structures/binary-tree/rb-tree.js +5 -17
  12. package/dist/data-structures/binary-tree/tree-multiset.d.ts +187 -18
  13. package/dist/data-structures/binary-tree/tree-multiset.js +716 -39
  14. package/dist/data-structures/graph/abstract-graph.d.ts +112 -52
  15. package/dist/data-structures/graph/abstract-graph.js +138 -72
  16. package/dist/data-structures/graph/directed-graph.d.ts +104 -101
  17. package/dist/data-structures/graph/directed-graph.js +134 -129
  18. package/dist/data-structures/graph/undirected-graph.d.ts +66 -65
  19. package/dist/data-structures/graph/undirected-graph.js +107 -106
  20. package/dist/data-structures/interfaces/abstract-binary-tree.d.ts +12 -18
  21. package/dist/data-structures/interfaces/abstract-graph.d.ts +2 -4
  22. package/dist/data-structures/interfaces/avl-tree.d.ts +2 -2
  23. package/dist/data-structures/interfaces/binary-tree.d.ts +1 -1
  24. package/dist/data-structures/interfaces/bst.d.ts +4 -5
  25. package/dist/data-structures/interfaces/rb-tree.d.ts +2 -3
  26. package/dist/data-structures/interfaces/tree-multiset.d.ts +7 -1
  27. package/dist/data-structures/tree/tree.d.ts +1 -4
  28. package/dist/data-structures/tree/tree.js +1 -12
  29. package/dist/data-structures/types/abstract-binary-tree.d.ts +10 -6
  30. package/dist/data-structures/types/abstract-binary-tree.js +9 -5
  31. package/dist/data-structures/types/avl-tree.d.ts +1 -1
  32. package/dist/data-structures/types/binary-tree.d.ts +1 -1
  33. package/dist/data-structures/types/bst.d.ts +1 -1
  34. package/dist/data-structures/types/bst.js +1 -1
  35. package/dist/data-structures/types/directed-graph.js +1 -1
  36. package/dist/data-structures/types/helpers.d.ts +1 -8
  37. package/dist/data-structures/types/rb-tree.d.ts +2 -0
  38. package/dist/data-structures/types/rb-tree.js +1 -1
  39. package/dist/data-structures/types/tree-multiset.d.ts +5 -5
  40. package/dist/utils/index.d.ts +1 -0
  41. package/dist/utils/index.js +1 -0
  42. package/dist/utils/types/index.d.ts +1 -0
  43. package/dist/utils/types/index.js +1 -0
  44. package/dist/utils/types/validate-type.d.ts +19 -0
  45. package/dist/utils/types/validate-type.js +2 -0
  46. package/dist/utils/utils.d.ts +2 -2
  47. package/dist/utils/utils.js +0 -62
  48. package/dist/utils/validate-type.d.ts +45 -0
  49. package/dist/utils/validate-type.js +58 -0
  50. package/package.json +5 -2
  51. package/backup/recursive-type/src/assets/complexities-diff.jpg +0 -0
  52. package/backup/recursive-type/src/assets/data-structure-complexities.jpg +0 -0
  53. package/backup/recursive-type/src/assets/logo.png +0 -0
  54. package/backup/recursive-type/src/assets/overview-diagram-of-data-structures.png +0 -0
  55. package/backup/recursive-type/src/data-structures/binary-tree/aa-tree.ts +0 -3
  56. package/backup/recursive-type/src/data-structures/binary-tree/avl-tree.ts +0 -288
  57. package/backup/recursive-type/src/data-structures/binary-tree/b-tree.ts +0 -3
  58. package/backup/recursive-type/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -78
  59. package/backup/recursive-type/src/data-structures/binary-tree/binary-tree.ts +0 -1502
  60. package/backup/recursive-type/src/data-structures/binary-tree/bst.ts +0 -503
  61. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  62. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  63. package/backup/recursive-type/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  64. package/backup/recursive-type/src/data-structures/binary-tree/index.ts +0 -11
  65. package/backup/recursive-type/src/data-structures/binary-tree/rb-tree.ts +0 -110
  66. package/backup/recursive-type/src/data-structures/binary-tree/segment-tree.ts +0 -243
  67. package/backup/recursive-type/src/data-structures/binary-tree/splay-tree.ts +0 -3
  68. package/backup/recursive-type/src/data-structures/binary-tree/tree-multiset.ts +0 -55
  69. package/backup/recursive-type/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  70. package/backup/recursive-type/src/data-structures/diagrams/README.md +0 -5
  71. package/backup/recursive-type/src/data-structures/graph/abstract-graph.ts +0 -985
  72. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  73. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  74. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  75. package/backup/recursive-type/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  76. package/backup/recursive-type/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  77. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  78. package/backup/recursive-type/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  79. package/backup/recursive-type/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  80. package/backup/recursive-type/src/data-structures/graph/diagrams/mst.jpg +0 -0
  81. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  82. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  83. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  84. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  85. package/backup/recursive-type/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  86. package/backup/recursive-type/src/data-structures/graph/directed-graph.ts +0 -478
  87. package/backup/recursive-type/src/data-structures/graph/index.ts +0 -3
  88. package/backup/recursive-type/src/data-structures/graph/undirected-graph.ts +0 -293
  89. package/backup/recursive-type/src/data-structures/hash/coordinate-map.ts +0 -67
  90. package/backup/recursive-type/src/data-structures/hash/coordinate-set.ts +0 -56
  91. package/backup/recursive-type/src/data-structures/hash/hash-table.ts +0 -3
  92. package/backup/recursive-type/src/data-structures/hash/index.ts +0 -6
  93. package/backup/recursive-type/src/data-structures/hash/pair.ts +0 -3
  94. package/backup/recursive-type/src/data-structures/hash/tree-map.ts +0 -3
  95. package/backup/recursive-type/src/data-structures/hash/tree-set.ts +0 -3
  96. package/backup/recursive-type/src/data-structures/heap/heap.ts +0 -176
  97. package/backup/recursive-type/src/data-structures/heap/index.ts +0 -3
  98. package/backup/recursive-type/src/data-structures/heap/max-heap.ts +0 -31
  99. package/backup/recursive-type/src/data-structures/heap/min-heap.ts +0 -34
  100. package/backup/recursive-type/src/data-structures/index.ts +0 -15
  101. package/backup/recursive-type/src/data-structures/interfaces/abstract-graph.ts +0 -42
  102. package/backup/recursive-type/src/data-structures/interfaces/avl-tree.ts +0 -1
  103. package/backup/recursive-type/src/data-structures/interfaces/binary-tree.ts +0 -56
  104. package/backup/recursive-type/src/data-structures/interfaces/bst.ts +0 -1
  105. package/backup/recursive-type/src/data-structures/interfaces/directed-graph.ts +0 -15
  106. package/backup/recursive-type/src/data-structures/interfaces/doubly-linked-list.ts +0 -1
  107. package/backup/recursive-type/src/data-structures/interfaces/heap.ts +0 -1
  108. package/backup/recursive-type/src/data-structures/interfaces/index.ts +0 -13
  109. package/backup/recursive-type/src/data-structures/interfaces/navigator.ts +0 -1
  110. package/backup/recursive-type/src/data-structures/interfaces/priority-queue.ts +0 -1
  111. package/backup/recursive-type/src/data-structures/interfaces/segment-tree.ts +0 -1
  112. package/backup/recursive-type/src/data-structures/interfaces/singly-linked-list.ts +0 -1
  113. package/backup/recursive-type/src/data-structures/interfaces/tree-multiset.ts +0 -1
  114. package/backup/recursive-type/src/data-structures/interfaces/undirected-graph.ts +0 -3
  115. package/backup/recursive-type/src/data-structures/linked-list/doubly-linked-list.ts +0 -573
  116. package/backup/recursive-type/src/data-structures/linked-list/index.ts +0 -3
  117. package/backup/recursive-type/src/data-structures/linked-list/singly-linked-list.ts +0 -490
  118. package/backup/recursive-type/src/data-structures/linked-list/skip-linked-list.ts +0 -3
  119. package/backup/recursive-type/src/data-structures/matrix/index.ts +0 -4
  120. package/backup/recursive-type/src/data-structures/matrix/matrix.ts +0 -27
  121. package/backup/recursive-type/src/data-structures/matrix/matrix2d.ts +0 -208
  122. package/backup/recursive-type/src/data-structures/matrix/navigator.ts +0 -122
  123. package/backup/recursive-type/src/data-structures/matrix/vector2d.ts +0 -316
  124. package/backup/recursive-type/src/data-structures/priority-queue/index.ts +0 -3
  125. package/backup/recursive-type/src/data-structures/priority-queue/max-priority-queue.ts +0 -49
  126. package/backup/recursive-type/src/data-structures/priority-queue/min-priority-queue.ts +0 -50
  127. package/backup/recursive-type/src/data-structures/priority-queue/priority-queue.ts +0 -354
  128. package/backup/recursive-type/src/data-structures/queue/deque.ts +0 -251
  129. package/backup/recursive-type/src/data-structures/queue/index.ts +0 -2
  130. package/backup/recursive-type/src/data-structures/queue/queue.ts +0 -120
  131. package/backup/recursive-type/src/data-structures/stack/index.ts +0 -1
  132. package/backup/recursive-type/src/data-structures/stack/stack.ts +0 -98
  133. package/backup/recursive-type/src/data-structures/tree/index.ts +0 -1
  134. package/backup/recursive-type/src/data-structures/tree/tree.ts +0 -80
  135. package/backup/recursive-type/src/data-structures/trie/index.ts +0 -1
  136. package/backup/recursive-type/src/data-structures/trie/trie.ts +0 -227
  137. package/backup/recursive-type/src/data-structures/types/abstract-graph.ts +0 -5
  138. package/backup/recursive-type/src/data-structures/types/avl-tree.ts +0 -8
  139. package/backup/recursive-type/src/data-structures/types/binary-tree.ts +0 -10
  140. package/backup/recursive-type/src/data-structures/types/bst.ts +0 -6
  141. package/backup/recursive-type/src/data-structures/types/directed-graph.ts +0 -8
  142. package/backup/recursive-type/src/data-structures/types/doubly-linked-list.ts +0 -1
  143. package/backup/recursive-type/src/data-structures/types/heap.ts +0 -5
  144. package/backup/recursive-type/src/data-structures/types/index.ts +0 -12
  145. package/backup/recursive-type/src/data-structures/types/navigator.ts +0 -13
  146. package/backup/recursive-type/src/data-structures/types/priority-queue.ts +0 -9
  147. package/backup/recursive-type/src/data-structures/types/segment-tree.ts +0 -1
  148. package/backup/recursive-type/src/data-structures/types/singly-linked-list.ts +0 -1
  149. package/backup/recursive-type/src/data-structures/types/tree-multiset.ts +0 -1
  150. package/backup/recursive-type/src/index.ts +0 -1
  151. package/backup/recursive-type/src/utils/index.ts +0 -2
  152. package/backup/recursive-type/src/utils/types/index.ts +0 -1
  153. package/backup/recursive-type/src/utils/types/utils.ts +0 -6
  154. package/backup/recursive-type/src/utils/utils.ts +0 -78
  155. package/docs/.nojekyll +0 -1
  156. package/docs/assets/highlight.css +0 -92
  157. package/docs/assets/main.js +0 -58
  158. package/docs/assets/search.js +0 -1
  159. package/docs/assets/style.css +0 -1367
  160. package/docs/classes/AVLTree.html +0 -2451
  161. package/docs/classes/AVLTreeNode.html +0 -499
  162. package/docs/classes/AaTree.html +0 -172
  163. package/docs/classes/AbstractBinaryTree.html +0 -2118
  164. package/docs/classes/AbstractBinaryTreeNode.html +0 -524
  165. package/docs/classes/AbstractEdge.html +0 -295
  166. package/docs/classes/AbstractGraph.html +0 -1043
  167. package/docs/classes/AbstractVertex.html +0 -258
  168. package/docs/classes/ArrayDeque.html +0 -439
  169. package/docs/classes/BST.html +0 -2297
  170. package/docs/classes/BSTNode.html +0 -503
  171. package/docs/classes/BTree.html +0 -172
  172. package/docs/classes/BinaryIndexedTree.html +0 -341
  173. package/docs/classes/BinaryTree.html +0 -2133
  174. package/docs/classes/BinaryTreeNode.html +0 -501
  175. package/docs/classes/Character.html +0 -220
  176. package/docs/classes/CoordinateMap.html +0 -483
  177. package/docs/classes/CoordinateSet.html +0 -444
  178. package/docs/classes/Deque.html +0 -975
  179. package/docs/classes/DirectedEdge.html +0 -366
  180. package/docs/classes/DirectedGraph.html +0 -1443
  181. package/docs/classes/DirectedVertex.html +0 -254
  182. package/docs/classes/DoublyLinkedList.html +0 -968
  183. package/docs/classes/DoublyLinkedListNode.html +0 -297
  184. package/docs/classes/HashTable.html +0 -172
  185. package/docs/classes/Heap.html +0 -423
  186. package/docs/classes/HeapItem.html +0 -255
  187. package/docs/classes/Matrix2D.html +0 -502
  188. package/docs/classes/MatrixNTI2D.html +0 -240
  189. package/docs/classes/MaxHeap.html +0 -436
  190. package/docs/classes/MaxPriorityQueue.html +0 -836
  191. package/docs/classes/MinHeap.html +0 -437
  192. package/docs/classes/MinPriorityQueue.html +0 -838
  193. package/docs/classes/Navigator.html +0 -313
  194. package/docs/classes/ObjectDeque.html +0 -455
  195. package/docs/classes/Pair.html +0 -172
  196. package/docs/classes/PriorityQueue.html +0 -760
  197. package/docs/classes/Queue.html +0 -392
  198. package/docs/classes/RBTree.html +0 -2388
  199. package/docs/classes/RBTreeNode.html +0 -516
  200. package/docs/classes/SegmentTree.html +0 -434
  201. package/docs/classes/SegmentTreeNode.html +0 -357
  202. package/docs/classes/SinglyLinkedList.html +0 -788
  203. package/docs/classes/SinglyLinkedListNode.html +0 -270
  204. package/docs/classes/SkipLinkedList.html +0 -172
  205. package/docs/classes/SplayTree.html +0 -172
  206. package/docs/classes/Stack.html +0 -368
  207. package/docs/classes/TreeMap.html +0 -172
  208. package/docs/classes/TreeMultiSet.html +0 -2297
  209. package/docs/classes/TreeMultiSetNode.html +0 -499
  210. package/docs/classes/TreeNode.html +0 -343
  211. package/docs/classes/TreeSet.html +0 -172
  212. package/docs/classes/Trie.html +0 -372
  213. package/docs/classes/TrieNode.html +0 -280
  214. package/docs/classes/TwoThreeTree.html +0 -172
  215. package/docs/classes/UndirectedEdge.html +0 -337
  216. package/docs/classes/UndirectedGraph.html +0 -1210
  217. package/docs/classes/UndirectedVertex.html +0 -254
  218. package/docs/classes/Vector2D.html +0 -805
  219. package/docs/enums/CP.html +0 -181
  220. package/docs/enums/FamilyPosition.html +0 -181
  221. package/docs/enums/LoopType.html +0 -182
  222. package/docs/enums/RBColor.html +0 -174
  223. package/docs/enums/TopologicalProperty.html +0 -181
  224. package/docs/index.html +0 -645
  225. package/docs/interfaces/IAVLTree.html +0 -1378
  226. package/docs/interfaces/IAVLTreeNode.html +0 -405
  227. package/docs/interfaces/IAbstractBinaryTree.html +0 -1124
  228. package/docs/interfaces/IAbstractBinaryTreeNode.html +0 -384
  229. package/docs/interfaces/IAbstractGraph.html +0 -433
  230. package/docs/interfaces/IBST.html +0 -1271
  231. package/docs/interfaces/IBSTNode.html +0 -408
  232. package/docs/interfaces/IDirectedGraph.html +0 -572
  233. package/docs/interfaces/IUNDirectedGraph.html +0 -465
  234. package/docs/modules.html +0 -262
  235. package/docs/types/AVLTreeOptions.html +0 -150
  236. package/docs/types/AbstractBinaryTreeNodeProperties.html +0 -152
  237. package/docs/types/AbstractBinaryTreeNodeProperty.html +0 -152
  238. package/docs/types/AbstractBinaryTreeOptions.html +0 -156
  239. package/docs/types/AbstractRecursiveBinaryTreeNode.html +0 -152
  240. package/docs/types/BSTComparator.html +0 -162
  241. package/docs/types/BSTOptions.html +0 -152
  242. package/docs/types/BinaryTreeDeletedResult.html +0 -159
  243. package/docs/types/BinaryTreeNodeId.html +0 -147
  244. package/docs/types/BinaryTreeNodePropertyName.html +0 -147
  245. package/docs/types/BinaryTreeOptions.html +0 -150
  246. package/docs/types/DFSOrderPattern.html +0 -147
  247. package/docs/types/DijkstraResult.html +0 -167
  248. package/docs/types/Direction.html +0 -147
  249. package/docs/types/EdgeId.html +0 -147
  250. package/docs/types/HeapOptions.html +0 -168
  251. package/docs/types/IdObject.html +0 -157
  252. package/docs/types/KeyValObject.html +0 -152
  253. package/docs/types/NavigatorParams.html +0 -181
  254. package/docs/types/NodeOrPropertyName.html +0 -147
  255. package/docs/types/PriorityQueueComparator.html +0 -167
  256. package/docs/types/PriorityQueueDFSOrderPattern.html +0 -147
  257. package/docs/types/PriorityQueueOptions.html +0 -161
  258. package/docs/types/RBTreeOptions.html +0 -150
  259. package/docs/types/RecursiveAVLTreeNode.html +0 -152
  260. package/docs/types/RecursiveBSTNode.html +0 -152
  261. package/docs/types/RecursiveBinaryTreeNode.html +0 -152
  262. package/docs/types/RecursiveTreeMultiSetNode.html +0 -152
  263. package/docs/types/SegmentTreeNodeVal.html +0 -147
  264. package/docs/types/TopologicalStatus.html +0 -147
  265. package/docs/types/TreeMultiSetOptions.html +0 -152
  266. package/docs/types/Turning.html +0 -147
  267. package/docs/types/VertexId.html +0 -147
  268. package/notes/bst.test.ts +0 -181
  269. package/notes/note.md +0 -34
@@ -65,10 +65,10 @@ var DirectedVertex = /** @class */ (function (_super) {
65
65
  __extends(DirectedVertex, _super);
66
66
  /**
67
67
  * The constructor function initializes a vertex with an optional value.
68
- * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
69
- * typically a unique identifier for each vertex in a graph.
70
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to specify the value
71
- * associated with the vertex.
68
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
69
+ * used to uniquely identify the vertex within a graph or data structure.
70
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
71
+ * vertex. If no value is provided, the vertex will be initialized with a default value.
72
72
  */
73
73
  function DirectedVertex(id, val) {
74
74
  return _super.call(this, id, val) || this;
@@ -83,11 +83,10 @@ var DirectedEdge = /** @class */ (function (_super) {
83
83
  * and value.
84
84
  * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
85
85
  * a graph.
86
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
87
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
88
- * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
89
- * If the weight is not provided, it will default to `undefined`.
90
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
86
+ * @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
87
+ * `VertexId`, which is likely a unique identifier for a vertex in a graph.
88
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
89
+ * @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value associated with
91
90
  * the edge.
92
91
  */
93
92
  function DirectedEdge(src, dest, weight, val) {
@@ -119,9 +118,11 @@ var DirectedEdge = /** @class */ (function (_super) {
119
118
  return DirectedEdge;
120
119
  }(abstract_graph_1.AbstractEdge));
121
120
  exports.DirectedEdge = DirectedEdge;
122
- // Strongly connected, One direction connected, Weakly connected
123
121
  var DirectedGraph = /** @class */ (function (_super) {
124
122
  __extends(DirectedGraph, _super);
123
+ /**
124
+ * The constructor function initializes an instance of a class.
125
+ */
125
126
  function DirectedGraph() {
126
127
  var _this = _super.call(this) || this;
127
128
  _this._outEdgeMap = new Map();
@@ -145,8 +146,15 @@ var DirectedGraph = /** @class */ (function (_super) {
145
146
  /**
146
147
  * 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.
147
148
  * 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.
148
- * @param id
149
- * @param val
149
+ */
150
+ /**
151
+ * The function creates a new vertex with an optional value and returns it.
152
+ * @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
153
+ * could be a number or a string depending on how you want to identify your vertices.
154
+ * @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
155
+ * it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
156
+ * assigned the same value as the 'id' parameter
157
+ * @returns a new instance of a DirectedVertex object, casted as type V.
150
158
  */
151
159
  DirectedGraph.prototype.createVertex = function (id, val) {
152
160
  return new DirectedVertex(id, val !== null && val !== void 0 ? val : id);
@@ -154,21 +162,27 @@ var DirectedGraph = /** @class */ (function (_super) {
154
162
  /**
155
163
  * 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.
156
164
  * 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.
157
- * @param src
158
- * @param dest
159
- * @param weight
160
- * @param val
165
+ */
166
+ /**
167
+ * The function creates a directed edge between two vertices with an optional weight and value.
168
+ * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
169
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
170
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
171
+ * weight is provided, it defaults to 1.
172
+ * @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
173
+ * is used to store additional information or data associated with the edge.
174
+ * @returns a new instance of a DirectedEdge object, casted as type E.
161
175
  */
162
176
  DirectedGraph.prototype.createEdge = function (src, dest, weight, val) {
163
177
  return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, val);
164
178
  };
165
179
  /**
166
- * The function `getEdge` returns the directed edge between two vertices, given their source and destination.
167
- * @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
168
- * DirectedVertex object or a VertexId.
169
- * @param {V | null | VertexId} destOrId - The `destOrId` parameter is the destination vertex or its
170
- * ID. It can be either a `DirectedVertex` object or a `VertexId` value.
171
- * @returns a E object or null.
180
+ * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
181
+ * @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
182
+ * @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
183
+ * destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
184
+ * destination is not specified.
185
+ * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
172
186
  */
173
187
  DirectedGraph.prototype.getEdge = function (srcOrId, destOrId) {
174
188
  var edges = [];
@@ -185,49 +199,10 @@ var DirectedGraph = /** @class */ (function (_super) {
185
199
  return edges[0] || null;
186
200
  };
187
201
  /**
188
- * The `addEdge` function adds a directed edge to a graph if the source and destination vertices exist.
189
- * @param edge - The parameter `edge` is of type `E`, which represents a directed edge in a graph. It
190
- * contains two properties:
191
- * @returns The method `addEdge` returns a boolean value. It returns `true` if the edge was successfully added to the
192
- * graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
193
- */
194
- DirectedGraph.prototype.addEdge = function (edge) {
195
- if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
196
- return false;
197
- }
198
- var srcVertex = this._getVertex(edge.src);
199
- var destVertex = this._getVertex(edge.dest);
200
- // TODO after no-non-null-assertion not ensure the logic
201
- if (srcVertex && destVertex) {
202
- var srcOutEdges = this._outEdgeMap.get(srcVertex);
203
- if (srcOutEdges) {
204
- srcOutEdges.push(edge);
205
- }
206
- else {
207
- this._outEdgeMap.set(srcVertex, [edge]);
208
- }
209
- var destInEdges = this._inEdgeMap.get(destVertex);
210
- if (destInEdges) {
211
- destInEdges.push(edge);
212
- }
213
- else {
214
- this._inEdgeMap.set(destVertex, [edge]);
215
- }
216
- return true;
217
- }
218
- else {
219
- return false;
220
- }
221
- };
222
- /**
223
- * The `removeEdgeBetween` function removes an edge between two vertices in a directed graph and returns the removed
224
- * edge, or null if the edge was not found.
225
- * @param {V | VertexId} srcOrId - The `srcOrId` parameter represents either a `V`
226
- * object or a `VertexId` value. It is used to specify the source vertex of the edge that you want to remove.
227
- * @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex of the
228
- * edge that you want to remove. It can be either a `V` object or a `VertexId` value.
229
- * @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
230
- * the edge does not exist.
202
+ * The function removes an edge between two vertices in a graph and returns the removed edge.
203
+ * @param {V | VertexId} srcOrId - The source vertex or its ID.
204
+ * @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
205
+ * @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
231
206
  */
232
207
  DirectedGraph.prototype.removeEdgeSrcToDest = function (srcOrId, destOrId) {
233
208
  var src = this._getVertex(srcOrId);
@@ -247,12 +222,10 @@ var DirectedGraph = /** @class */ (function (_super) {
247
222
  return removed;
248
223
  };
249
224
  /**
250
- * The `removeEdge` function removes a directed edge from a graph and returns the removed edge, or null if the edge was
251
- * not found.
252
- * @param edge - The `edge` parameter is an object of type `E`, which represents a directed edge in a
253
- * graph. It has two properties:
254
- * @returns The function `removeEdge` returns a `E` object if an edge is successfully removed, or `null`
255
- * if no edge is removed.
225
+ * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
226
+ * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
227
+ * and `dest`, which represent the source and destination vertices of the edge, respectively.
228
+ * @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
256
229
  */
257
230
  DirectedGraph.prototype.removeEdge = function (edge) {
258
231
  var removed = null;
@@ -271,12 +244,12 @@ var DirectedGraph = /** @class */ (function (_super) {
271
244
  return removed;
272
245
  };
273
246
  /**
274
- * The function removes all edges between two vertices and returns the removed edges.
275
- * @param {VertexId | V} v1 - The parameter `v1` represents either a `VertexId` or a `V` object. It is used to identify
276
- * the first vertex in the graph.
277
- * @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V`. It is used to identify the
278
- * second vertex involved in the edges that need to be removed.
279
- * @returns The function `removeEdgesBetween` returns an array of removed edges (`E[]`).
247
+ * The function removes edges between two vertices and returns the removed edges.
248
+ * @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
249
+ * unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
250
+ * @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
251
+ * the second vertex in the edge that needs to be removed.
252
+ * @returns an array of removed edges (E[]).
280
253
  */
281
254
  DirectedGraph.prototype.removeEdgesBetween = function (v1, v2) {
282
255
  var removed = [];
@@ -289,10 +262,10 @@ var DirectedGraph = /** @class */ (function (_super) {
289
262
  return removed;
290
263
  };
291
264
  /**
292
- * The function returns an array of incoming edges of a given vertex or vertex ID.
293
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
294
- * object or a `VertexId`.
295
- * @returns The method `incomingEdgesOf` returns an array of `E` objects.
265
+ * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
266
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
267
+ * (`VertexId`).
268
+ * @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
296
269
  */
297
270
  DirectedGraph.prototype.incomingEdgesOf = function (vertexOrId) {
298
271
  var target = this._getVertex(vertexOrId);
@@ -302,10 +275,10 @@ var DirectedGraph = /** @class */ (function (_super) {
302
275
  return [];
303
276
  };
304
277
  /**
305
- * The function `outgoingEdgesOf` returns an array of outgoing directed edges from a given vertex or vertex ID.
306
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
307
- * object or a `VertexId`.
308
- * @returns The method `outgoingEdgesOf` returns an array of `E` objects.
278
+ * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
279
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
280
+ * (`VertexId`).
281
+ * @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
309
282
  */
310
283
  DirectedGraph.prototype.outgoingEdgesOf = function (vertexOrId) {
311
284
  var target = this._getVertex(vertexOrId);
@@ -315,64 +288,58 @@ var DirectedGraph = /** @class */ (function (_super) {
315
288
  return [];
316
289
  };
317
290
  /**
318
- * The function "degreeOf" returns the total degree of a vertex in a directed graph, which is the sum of its out-degree
319
- * and in-degree.
320
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
321
- * `V`.
322
- * @returns The sum of the out-degree and in-degree of the given vertex or vertex ID.
291
+ * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
292
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
293
+ * @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
323
294
  */
324
295
  DirectedGraph.prototype.degreeOf = function (vertexOrId) {
325
296
  return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
326
297
  };
327
298
  /**
328
- * The function "inDegreeOf" returns the number of incoming edges for a given vertex or vertex ID in a directed graph.
329
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
330
- * `V`.
299
+ * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
300
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
331
301
  * @returns The number of incoming edges of the specified vertex or vertex ID.
332
302
  */
333
303
  DirectedGraph.prototype.inDegreeOf = function (vertexOrId) {
334
304
  return this.incomingEdgesOf(vertexOrId).length;
335
305
  };
336
306
  /**
337
- * The function "outDegreeOf" returns the number of outgoing edges from a given vertex.
338
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
339
- * `V`.
307
+ * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
308
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
340
309
  * @returns The number of outgoing edges from the specified vertex or vertex ID.
341
310
  */
342
311
  DirectedGraph.prototype.outDegreeOf = function (vertexOrId) {
343
312
  return this.outgoingEdgesOf(vertexOrId).length;
344
313
  };
345
314
  /**
346
- * The function "edgesOf" returns an array of both outgoing and incoming directed edges of a given vertex or vertex ID.
347
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
348
- * `V`.
349
- * @returns an array of directed edges.
315
+ * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
316
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
317
+ * @returns The function `edgesOf` returns an array of edges.
350
318
  */
351
319
  DirectedGraph.prototype.edgesOf = function (vertexOrId) {
352
320
  return __spreadArray(__spreadArray([], __read(this.outgoingEdgesOf(vertexOrId)), false), __read(this.incomingEdgesOf(vertexOrId)), false);
353
321
  };
354
322
  /**
355
- * The function "getEdgeSrc" returns the source vertex of a directed edge, or null if the edge does not exist.
356
- * @param e - A directed edge object of type E.
357
- * @returns either a DirectedVertex object or null.
323
+ * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
324
+ * @param {E} e - The parameter "e" is of type E, which represents an edge in a graph.
325
+ * @returns either a vertex object (V) or null.
358
326
  */
359
327
  DirectedGraph.prototype.getEdgeSrc = function (e) {
360
328
  return this._getVertex(e.src);
361
329
  };
362
330
  /**
363
- * The function "getEdgeDest" returns the destination vertex of a directed edge.
364
- * @param e - E - This is an object representing a directed edge in a graph. It contains information
365
- * about the source vertex, destination vertex, and any associated data.
366
- * @returns either a DirectedVertex object or null.
331
+ * The function "getEdgeDest" returns the destination vertex of an edge.
332
+ * @param {E} e - The parameter "e" is of type "E", which represents an edge in a graph.
333
+ * @returns either a vertex object of type V or null.
367
334
  */
368
335
  DirectedGraph.prototype.getEdgeDest = function (e) {
369
336
  return this._getVertex(e.dest);
370
337
  };
371
338
  /**
372
- * The function `getDestinations` returns an array of directed vertices that are the destinations of outgoing edges
373
- * from a given vertex.
374
- * @param {V | VertexId | null} vertex - The `vertex` parameter can be one of the following:
375
- * @returns an array of DirectedVertex objects.
339
+ * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
340
+ * @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
341
+ * find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
342
+ * @returns an array of vertices (V[]).
376
343
  */
377
344
  DirectedGraph.prototype.getDestinations = function (vertex) {
378
345
  var e_1, _a;
@@ -400,14 +367,17 @@ var DirectedGraph = /** @class */ (function (_super) {
400
367
  return destinations;
401
368
  };
402
369
  /**
403
- * The `topologicalSort` function performs a topological sort on a directed graph and returns the sorted vertices in
404
- * reverse order, or null if the graph contains a cycle.
405
- * @returns The function `topologicalSort()` returns an array of `V` or `VertexId` objects in
406
- * topological order, or `null` if there is a cycle in the graph.
370
+ * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
371
+ * in the sorted order, or null if the graph contains a cycle.
372
+ * @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
373
+ * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
374
+ * specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
375
+ * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
407
376
  */
408
- DirectedGraph.prototype.topologicalSort = function () {
377
+ DirectedGraph.prototype.topologicalSort = function (propertyName) {
409
378
  var e_2, _a, e_3, _b;
410
379
  var _this = this;
380
+ propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
411
381
  // When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
412
382
  // When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
413
383
  var statusMap = new Map();
@@ -469,11 +439,13 @@ var DirectedGraph = /** @class */ (function (_super) {
469
439
  }
470
440
  if (hasCycle)
471
441
  return null;
442
+ if (propertyName === 'id')
443
+ sorted = sorted.map(function (vertex) { return vertex instanceof DirectedVertex ? vertex.id : vertex; });
472
444
  return sorted.reverse();
473
445
  };
474
446
  /**
475
- * The `edgeSet` function returns an array of all directed edges in the graph.
476
- * @returns The `edgeSet()` method returns an array of `E` objects.
447
+ * The `edgeSet` function returns an array of all the edges in the graph.
448
+ * @returns The `edgeSet()` method returns an array of edges (`E[]`).
477
449
  */
478
450
  DirectedGraph.prototype.edgeSet = function () {
479
451
  var edges = [];
@@ -482,12 +454,11 @@ var DirectedGraph = /** @class */ (function (_super) {
482
454
  });
483
455
  return edges;
484
456
  };
485
- /**--- start find cycles --- */
486
457
  /**
487
- * The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a directed graph.
488
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
489
- * object or a `VertexId`.
490
- * @returns an array of DirectedVertex objects.
458
+ * The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
459
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
460
+ * (`VertexId`).
461
+ * @returns an array of vertices (V[]).
491
462
  */
492
463
  DirectedGraph.prototype.getNeighbors = function (vertexOrId) {
493
464
  var e_5, _a;
@@ -515,13 +486,12 @@ var DirectedGraph = /** @class */ (function (_super) {
515
486
  }
516
487
  return neighbors;
517
488
  };
518
- /**--- end find cycles --- */
519
489
  /**
520
- * The function "getEndsOfEdge" returns the source and destination vertices of a directed edge if it exists in the
521
- * graph, otherwise it returns null.
522
- * @param edge - A directed edge object with a generic type E.
523
- * @returns an array containing the starting and ending vertices of the given directed edge, or null if the edge does
524
- * not exist in the graph.
490
+ * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
491
+ * otherwise it returns null.
492
+ * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph.
493
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
494
+ * graph. If the edge does not exist, it returns `null`.
525
495
  */
526
496
  DirectedGraph.prototype.getEndsOfEdge = function (edge) {
527
497
  if (!this.hasEdge(edge.src, edge.dest)) {
@@ -536,6 +506,41 @@ var DirectedGraph = /** @class */ (function (_super) {
536
506
  return null;
537
507
  }
538
508
  };
509
+ /**
510
+ * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
511
+ * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph. It is the edge that
512
+ * needs to be added to the graph.
513
+ * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
514
+ * source or destination vertex does not exist in the graph.
515
+ */
516
+ DirectedGraph.prototype._addEdgeOnly = function (edge) {
517
+ if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
518
+ return false;
519
+ }
520
+ var srcVertex = this._getVertex(edge.src);
521
+ var destVertex = this._getVertex(edge.dest);
522
+ // TODO after no-non-null-assertion not ensure the logic
523
+ if (srcVertex && destVertex) {
524
+ var srcOutEdges = this._outEdgeMap.get(srcVertex);
525
+ if (srcOutEdges) {
526
+ srcOutEdges.push(edge);
527
+ }
528
+ else {
529
+ this._outEdgeMap.set(srcVertex, [edge]);
530
+ }
531
+ var destInEdges = this._inEdgeMap.get(destVertex);
532
+ if (destInEdges) {
533
+ destInEdges.push(edge);
534
+ }
535
+ else {
536
+ this._inEdgeMap.set(destVertex, [edge]);
537
+ }
538
+ return true;
539
+ }
540
+ else {
541
+ return false;
542
+ }
543
+ };
539
544
  DirectedGraph.prototype._setOutEdgeMap = function (value) {
540
545
  this._outEdgeMap = value;
541
546
  };
@@ -4,8 +4,8 @@ import { IUNDirectedGraph } from '../interfaces';
4
4
  export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
5
5
  /**
6
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.
7
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
8
+ * used to uniquely identify the vertex within a graph or network.
9
9
  * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
10
10
  * vertex. If no value is provided, the vertex will be initialized with a default value.
11
11
  */
@@ -13,14 +13,14 @@ export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
13
13
  }
14
14
  export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
15
15
  /**
16
- * The constructor function initializes an instance of a class with two vertex IDs, an optional weight, and an optional
16
+ * The constructor function creates an instance of a class with two vertex IDs, an optional weight, and an optional
17
17
  * value.
18
- * @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
18
+ * @param {VertexId} v1 - The first vertex ID of the edge.
19
19
  * @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
20
20
  * graph edge.
21
21
  * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
22
- * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
23
- * the edge.
22
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store a value associated
23
+ * with the edge.
24
24
  */
25
25
  constructor(v1: VertexId, v2: VertexId, weight?: number, val?: T);
26
26
  private _vertices;
@@ -28,99 +28,100 @@ export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
28
28
  set vertices(v: [VertexId, VertexId]);
29
29
  }
30
30
  export declare class UndirectedGraph<V extends UndirectedVertex<any> = UndirectedVertex, E extends UndirectedEdge<any> = UndirectedEdge> extends AbstractGraph<V, E> implements IUNDirectedGraph<V, E> {
31
+ /**
32
+ * The constructor initializes a new Map object to store edges.
33
+ */
31
34
  constructor();
32
35
  protected _edges: Map<V, E[]>;
33
36
  get edges(): Map<V, E[]>;
34
37
  /**
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 id
38
- * @param val
38
+ * The function creates a new vertex with an optional value and returns it.
39
+ * @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is used to distinguish one
40
+ * vertex from another in the graph.
41
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the vertex. If a value is provided,
42
+ * it will be used as the value of the vertex. If no value is provided, the `id` parameter will be used as the value of
43
+ * the vertex.
44
+ * @returns The method is returning a new instance of the `UndirectedVertex` class, casted as type `V`.
39
45
  */
40
46
  createVertex(id: VertexId, val?: V['val']): V;
41
47
  /**
42
- * The function createEdge creates an undirected edge between two vertices with an optional weight and value.
43
- * @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge. It is of type `VertexId`, which
44
- * could be a unique identifier or label for the vertex.
45
- * @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge. It is of type `VertexId`, which
46
- * is typically a unique identifier for a vertex in a graph.
47
- * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
48
- * weight is provided, the default value is 1.
48
+ * The function creates an undirected edge between two vertices with an optional weight and value.
49
+ * @param {VertexId} v1 - The parameter `v1` represents the first vertex of the edge.
50
+ * @param {VertexId} v2 - The parameter `v2` represents the second vertex of the edge.
51
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. If
52
+ * no weight is provided, it defaults to 1.
49
53
  * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type and
50
54
  * is used to store additional information or data associated with the edge.
51
- * @returns an instance of the UndirectedEdge class, casted as type E.
55
+ * @returns a new instance of the `UndirectedEdge` class, which is casted as type `E`.
52
56
  */
53
57
  createEdge(v1: VertexId, v2: VertexId, weight?: number, val?: E['val']): E;
54
58
  /**
55
- * The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
56
- * exists.
57
- * @param {V | null | VertexId} v1 - The parameter `v1` represents either an `V`
58
- * object, `null`, or a `VertexId`. It is used to specify one of the vertices of the edge.
59
- * @param {V | null | VertexId} v2 - The parameter `v2` represents either an `UndirectedVertex`
60
- * object or a `VertexId` (identifier) of an undirected vertex.
61
- * @returns an instance of `E` or `null`.
59
+ * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
60
+ * @param {V | null | VertexId} v1 - The parameter `v1` represents a vertex or vertex ID. It can be of type `V` (vertex
61
+ * object), `null`, or `VertexId` (a string or number representing the ID of a vertex).
62
+ * @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
63
+ * object), `null`, or `VertexId` (vertex ID).
64
+ * @returns an edge (E) or null.
62
65
  */
63
66
  getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
64
67
  /**
65
- * The function adds an undirected edge to a graph by updating the adjacency list.
66
- * @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
67
- * array of two vertices connected by the edge.
68
- * @returns a boolean value.
69
- */
70
- addEdge(edge: E): boolean;
71
- /**
72
- * The function removes an edge between two vertices in an undirected graph.
73
- * @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
74
- * a `VertexId`. It is used to specify one of the vertices of the edge that needs to be removed.
75
- * @param {V | VertexId} v2 - The parameter `v2` represents either an instance of the
76
- * `UndirectedVertex` class or a `VertexId`. It is used to identify the second vertex of the edge that needs to be
77
- * removed.
78
- * @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
79
- * between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
80
- * between them, the function returns `null`.
68
+ * The function removes an edge between two vertices in a graph and returns the removed edge.
69
+ * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
70
+ * @param {V | VertexId} v2 - V | VertexId - This parameter can be either a vertex object (V) or a vertex ID
71
+ * (VertexId). It represents the second vertex of the edge that needs to be removed.
72
+ * @returns the removed edge (E) if it exists, or null if either of the vertices (V) does not exist.
81
73
  */
82
74
  removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
83
75
  /**
84
- * The removeEdge function removes an edge between two vertices in an undirected graph.
85
- * @param edge - An object representing an undirected edge. It has a property called "vertices" which is an array
86
- * containing the two vertices connected by the edge.
87
- * @returns The method is returning an UndirectedEdge object or null.
76
+ * The removeEdge function removes an edge between two vertices in a graph.
77
+ * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
78
+ * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
88
79
  */
89
80
  removeEdge(edge: E): E | null;
90
81
  /**
91
- * The function "degreeOf" returns the degree of a given vertex in an undirected graph.
92
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
93
- * `V`.
94
- * @returns the degree of the vertex.
82
+ * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
83
+ * vertex.
84
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
85
+ * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
86
+ * edges connected to that vertex.
95
87
  */
96
88
  degreeOf(vertexOrId: VertexId | V): number;
97
89
  /**
98
- * The function "edgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
99
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
100
- * `V`.
101
- * @returns an array of UndirectedEdge objects.
90
+ * The function returns the edges of a given vertex or vertex ID.
91
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`. A `VertexId` is a
92
+ * unique identifier for a vertex in a graph, while `V` represents the type of the vertex.
93
+ * @returns an array of edges.
102
94
  */
103
95
  edgesOf(vertexOrId: VertexId | V): E[];
104
96
  /**
105
- * The function "edgeSet" returns an array of unique undirected edges from a set of edges.
106
- * @returns The method `edgeSet()` returns an array of `E` objects.
97
+ * The function "edgeSet" returns an array of unique edges from a set of edges.
98
+ * @returns The method `edgeSet()` returns an array of type `E[]`.
107
99
  */
108
100
  edgeSet(): E[];
109
101
  /**
110
- * The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
111
- * @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
112
- * `V` object or a `VertexId`. It represents the vertex for which we want to find the neighbors.
113
- * @returns an array of UndirectedVertex objects.
102
+ * The function "getNeighbors" returns an array of neighboring vertices for a given vertex or vertex ID.
103
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
104
+ * (`VertexId`).
105
+ * @returns an array of vertices (V[]).
114
106
  */
115
107
  getNeighbors(vertexOrId: V | VertexId): V[];
116
108
  /**
117
- * The function "getEndsOfEdge" returns the two vertices that form the ends of a given undirected edge, or null if the
118
- * edge does not exist in the graph.
119
- * @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
120
- * array containing two vertices that the edge connects.
121
- * @returns The function `getEndsOfEdge` returns an array containing the two ends of the given `edge` if the edge
122
- * exists in the graph. If the edge does not exist, it returns `null`.
109
+ * The function "getEndsOfEdge" returns the vertices at the ends of an edge if the edge exists in the graph, otherwise
110
+ * it returns null.
111
+ * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
112
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
113
+ * graph. If the edge does not exist, it returns `null`.
123
114
  */
124
115
  getEndsOfEdge(edge: E): [V, V] | null;
116
+ /**
117
+ * The function adds an edge to the graph by updating the adjacency list with the vertices of the edge.
118
+ * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
119
+ * @returns a boolean value.
120
+ */
121
+ protected _addEdgeOnly(edge: E): boolean;
122
+ /**
123
+ * The function sets the edges of a graph.
124
+ * @param v - A map where the keys are of type V and the values are arrays of type E.
125
+ */
125
126
  protected _setEdges(v: Map<V, E[]>): void;
126
127
  }