data-structure-typed 1.18.0 → 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 (268) 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 +8 -16
  108. package/dist/data-structures/binary-tree/binary-tree.d.ts +99 -98
  109. package/dist/data-structures/binary-tree/binary-tree.js +70 -65
  110. package/dist/data-structures/binary-tree/bst.d.ts +21 -21
  111. package/dist/data-structures/binary-tree/bst.js +15 -17
  112. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -2
  113. package/dist/data-structures/binary-tree/rb-tree.js +68 -5
  114. package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -8
  115. package/dist/data-structures/binary-tree/tree-multiset.js +7 -6
  116. package/dist/data-structures/graph/abstract-graph.d.ts +56 -58
  117. package/dist/data-structures/graph/abstract-graph.js +84 -68
  118. package/dist/data-structures/graph/directed-graph.d.ts +127 -96
  119. package/dist/data-structures/graph/directed-graph.js +161 -109
  120. package/dist/data-structures/graph/undirected-graph.d.ts +82 -59
  121. package/dist/data-structures/graph/undirected-graph.js +99 -72
  122. package/dist/data-structures/hash/coordinate-set.d.ts +1 -1
  123. package/dist/data-structures/index.d.ts +1 -0
  124. package/dist/data-structures/index.js +1 -0
  125. package/dist/data-structures/interfaces/abstract-graph.d.ts +22 -0
  126. package/dist/data-structures/interfaces/abstract-graph.js +2 -0
  127. package/dist/data-structures/interfaces/avl-tree.d.ts +1 -0
  128. package/dist/data-structures/interfaces/avl-tree.js +2 -0
  129. package/dist/data-structures/interfaces/binary-tree.d.ts +27 -0
  130. package/dist/data-structures/interfaces/binary-tree.js +2 -0
  131. package/dist/data-structures/interfaces/bst.d.ts +1 -0
  132. package/dist/data-structures/interfaces/bst.js +2 -0
  133. package/dist/data-structures/interfaces/directed-graph.d.ts +9 -0
  134. package/dist/data-structures/interfaces/directed-graph.js +2 -0
  135. package/dist/data-structures/interfaces/doubly-linked-list.d.ts +1 -0
  136. package/dist/data-structures/interfaces/doubly-linked-list.js +2 -0
  137. package/dist/data-structures/interfaces/heap.d.ts +1 -0
  138. package/dist/data-structures/interfaces/heap.js +2 -0
  139. package/dist/data-structures/interfaces/index.d.ts +13 -0
  140. package/dist/data-structures/interfaces/index.js +29 -0
  141. package/dist/data-structures/interfaces/navigator.d.ts +1 -0
  142. package/dist/data-structures/interfaces/navigator.js +2 -0
  143. package/dist/data-structures/interfaces/priority-queue.d.ts +1 -0
  144. package/dist/data-structures/interfaces/priority-queue.js +2 -0
  145. package/dist/data-structures/interfaces/segment-tree.d.ts +1 -0
  146. package/dist/data-structures/interfaces/segment-tree.js +2 -0
  147. package/dist/data-structures/interfaces/singly-linked-list.d.ts +1 -0
  148. package/dist/data-structures/interfaces/singly-linked-list.js +2 -0
  149. package/dist/data-structures/interfaces/tree-multiset.d.ts +1 -0
  150. package/dist/data-structures/interfaces/tree-multiset.js +2 -0
  151. package/dist/data-structures/interfaces/undirected-graph.d.ts +2 -0
  152. package/dist/data-structures/interfaces/undirected-graph.js +2 -0
  153. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  154. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  155. package/dist/data-structures/priority-queue/priority-queue.d.ts +1 -1
  156. package/dist/data-structures/priority-queue/priority-queue.js +4 -4
  157. package/dist/data-structures/queue/deque.d.ts +5 -5
  158. package/dist/data-structures/queue/deque.js +6 -6
  159. package/dist/data-structures/queue/queue.d.ts +1 -1
  160. package/dist/data-structures/stack/stack.d.ts +1 -1
  161. package/dist/data-structures/types/abstract-graph.d.ts +1 -20
  162. package/dist/data-structures/types/avl-tree.d.ts +5 -4
  163. package/dist/data-structures/types/binary-tree.d.ts +6 -5
  164. package/dist/data-structures/types/bst.d.ts +4 -3
  165. package/dist/data-structures/types/directed-graph.d.ts +5 -9
  166. package/dist/data-structures/types/directed-graph.js +7 -0
  167. package/dist/data-structures/types/heap.d.ts +2 -2
  168. package/dist/data-structures/types/index.d.ts +0 -1
  169. package/dist/data-structures/types/index.js +0 -1
  170. package/dist/data-structures/types/navigator.d.ts +2 -2
  171. package/dist/data-structures/types/priority-queue.d.ts +2 -2
  172. package/dist/data-structures/types/tree-multiset.d.ts +3 -4
  173. package/docs/assets/search.js +1 -1
  174. package/docs/classes/AVLTree.html +288 -287
  175. package/docs/classes/AVLTreeNode.html +106 -63
  176. package/docs/classes/AaTree.html +14 -12
  177. package/docs/classes/AbstractEdge.html +68 -34
  178. package/docs/classes/AbstractGraph.html +219 -114
  179. package/docs/classes/AbstractVertex.html +71 -30
  180. package/docs/classes/ArrayDeque.html +27 -25
  181. package/docs/classes/BST.html +279 -273
  182. package/docs/classes/BSTNode.html +106 -57
  183. package/docs/classes/BTree.html +14 -12
  184. package/docs/classes/BinaryIndexedTree.html +22 -20
  185. package/docs/classes/BinaryTree.html +283 -277
  186. package/docs/classes/BinaryTreeNode.html +111 -63
  187. package/docs/classes/Character.html +17 -15
  188. package/docs/classes/CoordinateMap.html +22 -20
  189. package/docs/classes/CoordinateSet.html +23 -21
  190. package/docs/classes/Deque.html +47 -45
  191. package/docs/classes/DirectedEdge.html +74 -41
  192. package/docs/classes/DirectedGraph.html +444 -208
  193. package/docs/classes/DirectedVertex.html +63 -36
  194. package/docs/classes/DoublyLinkedList.html +52 -50
  195. package/docs/classes/DoublyLinkedListNode.html +24 -22
  196. package/docs/classes/HashTable.html +14 -12
  197. package/docs/classes/Heap.html +29 -27
  198. package/docs/classes/HeapItem.html +21 -19
  199. package/docs/classes/Matrix2D.html +29 -27
  200. package/docs/classes/MatrixNTI2D.html +17 -15
  201. package/docs/classes/MaxHeap.html +29 -27
  202. package/docs/classes/MaxPriorityQueue.html +67 -60
  203. package/docs/classes/MinHeap.html +29 -27
  204. package/docs/classes/MinPriorityQueue.html +67 -60
  205. package/docs/classes/Navigator.html +24 -22
  206. package/docs/classes/ObjectDeque.html +62 -50
  207. package/docs/classes/Pair.html +14 -12
  208. package/docs/classes/PriorityQueue.html +62 -55
  209. package/docs/classes/Queue.html +29 -27
  210. package/docs/classes/SegmentTree.html +30 -28
  211. package/docs/classes/SegmentTreeNode.html +33 -31
  212. package/docs/classes/SinglyLinkedList.html +49 -47
  213. package/docs/classes/SinglyLinkedListNode.html +21 -19
  214. package/docs/classes/SkipLinkedList.html +14 -12
  215. package/docs/classes/SplayTree.html +14 -12
  216. package/docs/classes/Stack.html +27 -25
  217. package/docs/classes/TreeMap.html +14 -12
  218. package/docs/classes/TreeMultiSet.html +277 -270
  219. package/docs/classes/TreeNode.html +29 -27
  220. package/docs/classes/TreeSet.html +14 -12
  221. package/docs/classes/Trie.html +26 -24
  222. package/docs/classes/TrieNode.html +24 -22
  223. package/docs/classes/TwoThreeTree.html +14 -12
  224. package/docs/classes/UndirectedEdge.html +70 -51
  225. package/docs/classes/UndirectedGraph.html +344 -161
  226. package/docs/classes/UndirectedVertex.html +63 -36
  227. package/docs/classes/Vector2D.html +41 -39
  228. package/docs/enums/CP.html +17 -15
  229. package/docs/enums/FamilyPosition.html +17 -15
  230. package/docs/enums/LoopType.html +16 -14
  231. package/docs/{interfaces/AVLTreeDeleted.html → enums/TopologicalProperty.html} +43 -43
  232. package/docs/index.html +195 -68
  233. package/docs/interfaces/{HeapOptions.html → IBinaryTree.html} +39 -32
  234. package/docs/interfaces/IBinaryTreeNode.html +383 -0
  235. package/docs/interfaces/IDirectedGraph.html +20 -18
  236. package/docs/interfaces/IGraph.html +118 -88
  237. package/docs/interfaces/{PriorityQueueOptions.html → IUNDirectedGraph.html} +22 -53
  238. package/docs/modules.html +25 -21
  239. package/docs/types/{ToThunkFn.html → AVLTreeDeleted.html} +27 -21
  240. package/docs/types/BSTComparator.html +14 -12
  241. package/docs/types/BSTDeletedResult.html +19 -17
  242. package/docs/types/BinaryTreeDeleted.html +19 -17
  243. package/docs/types/BinaryTreeNodeId.html +14 -12
  244. package/docs/types/BinaryTreeNodePropertyName.html +14 -12
  245. package/docs/types/DFSOrderPattern.html +14 -12
  246. package/docs/types/DijkstraResult.html +14 -12
  247. package/docs/types/Direction.html +14 -12
  248. package/docs/types/{TrlFn.html → EdgeId.html} +18 -29
  249. package/docs/types/{TrlAsyncFn.html → HeapOptions.html} +29 -19
  250. package/docs/types/NavigatorParams.html +164 -0
  251. package/docs/types/NodeOrPropertyName.html +14 -12
  252. package/docs/types/PriorityQueueComparator.html +14 -12
  253. package/docs/types/PriorityQueueDFSOrderPattern.html +14 -12
  254. package/docs/types/{SpecifyOptional.html → PriorityQueueOptions.html} +28 -19
  255. package/docs/types/RecursiveAVLTreeNode.html +135 -0
  256. package/docs/types/{Thunk.html → RecursiveBSTNode.html} +23 -24
  257. package/docs/types/RecursiveBinaryTreeNode.html +135 -0
  258. package/docs/types/ResultByProperty.html +17 -15
  259. package/docs/types/ResultsByProperty.html +17 -15
  260. package/docs/types/SegmentTreeNodeVal.html +14 -12
  261. package/docs/types/TopologicalStatus.html +14 -12
  262. package/docs/types/TreeMultiSetDeletedResult.html +19 -17
  263. package/docs/types/Turning.html +14 -12
  264. package/docs/types/VertexId.html +14 -12
  265. package/notes/note.md +8 -1
  266. package/package.json +10 -2
  267. package/docs/classes/RBTree.html +0 -153
  268. package/docs/interfaces/NavigatorParams.html +0 -200
@@ -64,12 +64,14 @@ var abstract_graph_1 = require("./abstract-graph");
64
64
  var DirectedVertex = /** @class */ (function (_super) {
65
65
  __extends(DirectedVertex, _super);
66
66
  /**
67
- * The constructor function initializes an object with a given id.
68
- * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
69
- * vertex within a graph or network.
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.
70
72
  */
71
- function DirectedVertex(id) {
72
- return _super.call(this, id) || this;
73
+ function DirectedVertex(id, val) {
74
+ return _super.call(this, id, val) || this;
73
75
  }
74
76
  return DirectedVertex;
75
77
  }(abstract_graph_1.AbstractVertex));
@@ -77,16 +79,19 @@ exports.DirectedVertex = DirectedVertex;
77
79
  var DirectedEdge = /** @class */ (function (_super) {
78
80
  __extends(DirectedEdge, _super);
79
81
  /**
80
- * The constructor function initializes the source and destination vertices of an edge, with an optional weight.
82
+ * The constructor function initializes the source and destination vertices of an edge, along with an optional weight
83
+ * and value.
81
84
  * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
82
85
  * a graph.
83
- * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex. It represents the vertex
84
- * to which an edge is directed.
85
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
86
- * between two vertices.
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
91
+ * the edge.
87
92
  */
88
- function DirectedEdge(src, dest, weight) {
89
- var _this = _super.call(this, weight) || this;
93
+ function DirectedEdge(src, dest, weight, val) {
94
+ var _this = _super.call(this, weight, val) || this;
90
95
  _this._src = src;
91
96
  _this._dest = dest;
92
97
  return _this;
@@ -117,25 +122,63 @@ exports.DirectedEdge = DirectedEdge;
117
122
  // Strongly connected, One direction connected, Weakly connected
118
123
  var DirectedGraph = /** @class */ (function (_super) {
119
124
  __extends(DirectedGraph, _super);
120
- function DirectedGraph() {
125
+ function DirectedGraph(vertexConstructor, edgeConstructor) {
121
126
  var _this = _super.call(this) || this;
122
127
  _this._outEdgeMap = new Map();
123
128
  _this._inEdgeMap = new Map();
129
+ _this._vertexConstructor = vertexConstructor;
130
+ _this._edgeConstructor = edgeConstructor;
124
131
  return _this;
125
132
  }
133
+ Object.defineProperty(DirectedGraph.prototype, "outEdgeMap", {
134
+ get: function () {
135
+ return this._outEdgeMap;
136
+ },
137
+ enumerable: false,
138
+ configurable: true
139
+ });
140
+ Object.defineProperty(DirectedGraph.prototype, "inEdgeMap", {
141
+ get: function () {
142
+ return this._inEdgeMap;
143
+ },
144
+ enumerable: false,
145
+ configurable: true
146
+ });
147
+ /**
148
+ * 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.
149
+ * 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.
150
+ * @param id
151
+ * @param val
152
+ */
153
+ DirectedGraph.prototype._createVertex = function (id, val) {
154
+ return new this._vertexConstructor(id, val);
155
+ };
156
+ /**
157
+ * 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.
158
+ * 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.
159
+ * @param src
160
+ * @param dest
161
+ * @param weight
162
+ * @param val
163
+ */
164
+ DirectedGraph.prototype._createEdge = function (src, dest, weight, val) {
165
+ if (weight === undefined || weight === null)
166
+ weight = 1;
167
+ return new this._edgeConstructor(src, dest, weight, val);
168
+ };
126
169
  /**
127
- * The function `getEdge` returns the first edge between two vertices, given their source and destination.
128
- * @param {V | null | VertexId} srcOrId - The `srcOrId` parameter can be either a vertex object (`V`), a vertex ID
129
- * (`VertexId`), or `null`. It represents the source vertex of the edge.
130
- * @param {V | null | VertexId} destOrId - The `destOrId` parameter is either a vertex object (`V`), a vertex ID
131
- * (`VertexId`), or `null`. It represents the destination vertex of the edge.
132
- * @returns an edge (E) or null.
170
+ * The function `getEdge` returns the directed edge between two vertices, given their source and destination.
171
+ * @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a
172
+ * DirectedVertex object or a VertexId.
173
+ * @param {V | null | VertexId} destOrId - The `destOrId` parameter is the destination vertex or its
174
+ * ID. It can be either a `DirectedVertex` object or a `VertexId` value.
175
+ * @returns a E object or null.
133
176
  */
134
177
  DirectedGraph.prototype.getEdge = function (srcOrId, destOrId) {
135
178
  var edges = [];
136
179
  if (srcOrId !== null && destOrId !== null) {
137
- var src = this.getVertex(srcOrId);
138
- var dest_1 = this.getVertex(destOrId);
180
+ var src = this._getVertex(srcOrId);
181
+ var dest_1 = this._getVertex(destOrId);
139
182
  if (src && dest_1) {
140
183
  var srcOutEdges = this._outEdgeMap.get(src);
141
184
  if (srcOutEdges) {
@@ -146,18 +189,18 @@ var DirectedGraph = /** @class */ (function (_super) {
146
189
  return edges[0] || null;
147
190
  };
148
191
  /**
149
- * The `addEdge` function adds an edge to a graph if the source and destination vertices exist.
150
- * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in the graph. It contains
151
- * information about the source vertex (`src`) and the destination vertex (`dest`) of the edge.
152
- * @returns The `addEdge` function returns a boolean value. It returns `true` if the edge was successfully added to the
153
- * graph, and `false` if either the source or destination vertices of the edge are not present in the graph.
192
+ * The `addEdge` function adds a directed edge to a graph if the source and destination vertices exist.
193
+ * @param edge - The parameter `edge` is of type `E`, which represents a directed edge in a graph. It
194
+ * contains two properties:
195
+ * @returns The method `addEdge` returns a boolean value. It returns `true` if the edge was successfully added to the
196
+ * graph, and `false` if either the source or destination vertex of the edge is not present in the graph.
154
197
  */
155
198
  DirectedGraph.prototype.addEdge = function (edge) {
156
199
  if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
157
200
  return false;
158
201
  }
159
- var srcVertex = this.getVertex(edge.src);
160
- var destVertex = this.getVertex(edge.dest);
202
+ var srcVertex = this._getVertex(edge.src);
203
+ var destVertex = this._getVertex(edge.dest);
161
204
  // TODO after no-non-null-assertion not ensure the logic
162
205
  if (srcVertex && destVertex) {
163
206
  var srcOutEdges = this._outEdgeMap.get(srcVertex);
@@ -181,18 +224,18 @@ var DirectedGraph = /** @class */ (function (_super) {
181
224
  }
182
225
  };
183
226
  /**
184
- * The function removes an edge between two vertices in a directed graph and returns the removed edge.
185
- * @param {V | VertexId} srcOrId - The source vertex or its ID.
186
- * @param {V | VertexId} destOrId - The `destOrId` parameter in the `removeEdgeBetween` function represents the
187
- * destination vertex of the edge that needs to be removed. It can be either a vertex object (`V`) or a vertex ID
188
- * (`VertexId`).
189
- * @returns The function `removeEdgeBetween` returns the removed edge (`E`) if the edge between the source and
190
- * destination vertices is successfully removed. If either the source or destination vertex is not found, or if the
191
- * edge does not exist, it returns `null`.
227
+ * The `removeEdgeBetween` function removes an edge between two vertices in a directed graph and returns the removed
228
+ * edge, or null if the edge was not found.
229
+ * @param {V | VertexId} srcOrId - The `srcOrId` parameter represents either a `V`
230
+ * object or a `VertexId` value. It is used to specify the source vertex of the edge that you want to remove.
231
+ * @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex of the
232
+ * edge that you want to remove. It can be either a `V` object or a `VertexId` value.
233
+ * @returns The function `removeEdgeBetween` returns the removed edge (`E`) if it exists, or `null` if
234
+ * the edge does not exist.
192
235
  */
193
236
  DirectedGraph.prototype.removeEdgeBetween = function (srcOrId, destOrId) {
194
- var src = this.getVertex(srcOrId);
195
- var dest = this.getVertex(destOrId);
237
+ var src = this._getVertex(srcOrId);
238
+ var dest = this._getVertex(destOrId);
196
239
  var removed = null;
197
240
  if (!src || !dest) {
198
241
  return null;
@@ -216,16 +259,17 @@ var DirectedGraph = /** @class */ (function (_super) {
216
259
  return removed;
217
260
  };
218
261
  /**
219
- * The removeEdge function removes an edge from a graph and returns the removed edge, or null if the edge was not
220
- * found.
221
- * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
222
- * and `dest`, which represent the source and destination vertices of the edge, respectively.
223
- * @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
262
+ * The `removeEdge` function removes a directed edge from a graph and returns the removed edge, or null if the edge was
263
+ * not found.
264
+ * @param edge - The `edge` parameter is an object of type `E`, which represents a directed edge in a
265
+ * graph. It has two properties:
266
+ * @returns The function `removeEdge` returns a `E` object if an edge is successfully removed, or `null`
267
+ * if no edge is removed.
224
268
  */
225
269
  DirectedGraph.prototype.removeEdge = function (edge) {
226
270
  var removed = null;
227
- var src = this.getVertex(edge.src);
228
- var dest = this.getVertex(edge.dest);
271
+ var src = this._getVertex(edge.src);
272
+ var dest = this._getVertex(edge.dest);
229
273
  if (src && dest) {
230
274
  var srcOutEdges = this._outEdgeMap.get(src);
231
275
  if (srcOutEdges && srcOutEdges.length > 0) {
@@ -240,95 +284,99 @@ var DirectedGraph = /** @class */ (function (_super) {
240
284
  };
241
285
  /**
242
286
  * The function removeAllEdges removes all edges between two vertices.
243
- * @param {VertexId | V} src - The `src` parameter represents the source vertex from which the edges will be removed.
244
- * It can be either a `VertexId` or a `V` type, which represents the identifier or object of the vertex.
245
- * @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It can be either a
246
- * `VertexId` or a vertex object `V`.
247
- * @returns An empty array is being returned.
287
+ * @param {VertexId | V} src - The `src` parameter can be either a `VertexId` or a `V`.
288
+ * @param {VertexId | V} dest - The `dest` parameter represents the destination vertex of an edge. It
289
+ * can be either a `VertexId` or a `V`.
290
+ * @returns An empty array of DirectedEdge objects is being returned.
248
291
  */
249
292
  DirectedGraph.prototype.removeAllEdges = function (src, dest) {
250
293
  return [];
251
294
  };
252
295
  /**
253
- * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
254
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
255
- * (`VertexId`).
256
- * @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
296
+ * The function returns an array of incoming edges of a given vertex or vertex ID.
297
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
298
+ * object or a `VertexId`.
299
+ * @returns The method `incomingEdgesOf` returns an array of `E` objects.
257
300
  */
258
301
  DirectedGraph.prototype.incomingEdgesOf = function (vertexOrId) {
259
- var target = this.getVertex(vertexOrId);
302
+ var target = this._getVertex(vertexOrId);
260
303
  if (target) {
261
- return this._inEdgeMap.get(target) || [];
304
+ return this.inEdgeMap.get(target) || [];
262
305
  }
263
306
  return [];
264
307
  };
265
308
  /**
266
- * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
267
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
268
- * (`VertexId`).
269
- * @returns The method `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
309
+ * The function `outgoingEdgesOf` returns an array of outgoing directed edges from a given vertex or vertex ID.
310
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
311
+ * object or a `VertexId`.
312
+ * @returns The method `outgoingEdgesOf` returns an array of `E` objects.
270
313
  */
271
314
  DirectedGraph.prototype.outgoingEdgesOf = function (vertexOrId) {
272
- var target = this.getVertex(vertexOrId);
315
+ var target = this._getVertex(vertexOrId);
273
316
  if (target) {
274
317
  return this._outEdgeMap.get(target) || [];
275
318
  }
276
319
  return [];
277
320
  };
278
321
  /**
279
- * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
280
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
281
- * @returns the sum of the out-degree and in-degree of the specified vertex or vertex ID.
322
+ * The function "degreeOf" returns the total degree of a vertex in a directed graph, which is the sum of its out-degree
323
+ * and in-degree.
324
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
325
+ * `V`.
326
+ * @returns The sum of the out-degree and in-degree of the given vertex or vertex ID.
282
327
  */
283
328
  DirectedGraph.prototype.degreeOf = function (vertexOrId) {
284
329
  return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
285
330
  };
286
331
  /**
287
- * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
288
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
332
+ * The function "inDegreeOf" returns the number of incoming edges for a given vertex or vertex ID in a directed graph.
333
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
334
+ * `V`.
289
335
  * @returns The number of incoming edges of the specified vertex or vertex ID.
290
336
  */
291
337
  DirectedGraph.prototype.inDegreeOf = function (vertexOrId) {
292
338
  return this.incomingEdgesOf(vertexOrId).length;
293
339
  };
294
340
  /**
295
- * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
296
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
341
+ * The function "outDegreeOf" returns the number of outgoing edges from a given vertex.
342
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
343
+ * `V`.
297
344
  * @returns The number of outgoing edges from the specified vertex or vertex ID.
298
345
  */
299
346
  DirectedGraph.prototype.outDegreeOf = function (vertexOrId) {
300
347
  return this.outgoingEdgesOf(vertexOrId).length;
301
348
  };
302
349
  /**
303
- * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
304
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
305
- * @returns The function `edgesOf` returns an array of edges.
350
+ * The function "edgesOf" returns an array of both outgoing and incoming directed edges of a given vertex or vertex ID.
351
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a
352
+ * `V`.
353
+ * @returns an array of directed edges.
306
354
  */
307
355
  DirectedGraph.prototype.edgesOf = function (vertexOrId) {
308
356
  return __spreadArray(__spreadArray([], __read(this.outgoingEdgesOf(vertexOrId)), false), __read(this.incomingEdgesOf(vertexOrId)), false);
309
357
  };
310
358
  /**
311
- * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
312
- * @param {E} e - E - an edge object
313
- * @returns the source vertex of the given edge, or null if the edge does not exist.
359
+ * The function "getEdgeSrc" returns the source vertex of a directed edge, or null if the edge does not exist.
360
+ * @param e - A directed edge object of type E.
361
+ * @returns either a DirectedVertex object or null.
314
362
  */
315
363
  DirectedGraph.prototype.getEdgeSrc = function (e) {
316
- return this.getVertex(e.src);
364
+ return this._getVertex(e.src);
317
365
  };
318
366
  /**
319
- * The function "getEdgeDest" returns the vertex associated with the destination of an edge.
320
- * @param {E} e - The parameter `e` is of type `E`, which represents an edge in a graph.
321
- * @returns either a vertex object (of type V) or null.
367
+ * The function "getEdgeDest" returns the destination vertex of a directed edge.
368
+ * @param e - E - This is an object representing a directed edge in a graph. It contains information
369
+ * about the source vertex, destination vertex, and any associated data.
370
+ * @returns either a DirectedVertex object or null.
322
371
  */
323
372
  DirectedGraph.prototype.getEdgeDest = function (e) {
324
- return this.getVertex(e.dest);
373
+ return this._getVertex(e.dest);
325
374
  };
326
375
  /**
327
- * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
328
- * @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
329
- * find the destinations. It can be either a `V` object, a `VertexId` (which is a unique identifier for a vertex), or
330
- * `null` if we want to find destinations from all vertices.
331
- * @returns an array of vertices (V[]).
376
+ * The function `getDestinations` returns an array of directed vertices that are the destinations of outgoing edges
377
+ * from a given vertex.
378
+ * @param {V | VertexId | null} vertex - The `vertex` parameter can be one of the following:
379
+ * @returns an array of DirectedVertex objects.
332
380
  */
333
381
  DirectedGraph.prototype.getDestinations = function (vertex) {
334
382
  var e_1, _a;
@@ -355,14 +403,11 @@ var DirectedGraph = /** @class */ (function (_super) {
355
403
  }
356
404
  return destinations;
357
405
  };
358
- /**--- start find cycles --- */
359
406
  /**
360
- * when stored with adjacency list time: O(V+E)
361
- * when stored with adjacency matrix time: O(V^2)
362
- * The `topologicalSort` function performs a topological sort on a graph and returns the sorted vertices in reverse
363
- * order, or null if the graph contains a cycle.
364
- * @returns The function `topologicalSort()` returns an array of vertices in topological order if there is no cycle in
365
- * the graph. If there is a cycle, it returns `null`.
407
+ * The `topologicalSort` function performs a topological sort on a directed graph and returns the sorted vertices in
408
+ * reverse order, or null if the graph contains a cycle.
409
+ * @returns The function `topologicalSort()` returns an array of `V` or `VertexId` objects in
410
+ * topological order, or `null` if there is a cycle in the graph.
366
411
  */
367
412
  DirectedGraph.prototype.topologicalSort = function () {
368
413
  var e_2, _a, e_3, _b;
@@ -371,7 +416,7 @@ var DirectedGraph = /** @class */ (function (_super) {
371
416
  // When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
372
417
  var statusMap = new Map();
373
418
  try {
374
- for (var _c = __values(this._vertices), _d = _c.next(); !_d.done; _d = _c.next()) {
419
+ for (var _c = __values(this.vertices), _d = _c.next(); !_d.done; _d = _c.next()) {
375
420
  var entry = _d.value;
376
421
  statusMap.set(entry[1], 0);
377
422
  }
@@ -412,7 +457,7 @@ var DirectedGraph = /** @class */ (function (_super) {
412
457
  sorted.push(cur);
413
458
  };
414
459
  try {
415
- for (var _e = __values(this._vertices), _f = _e.next(); !_f.done; _f = _e.next()) {
460
+ for (var _e = __values(this.vertices), _f = _e.next(); !_f.done; _f = _e.next()) {
416
461
  var entry = _f.value;
417
462
  if (statusMap.get(entry[1]) === 0) {
418
463
  dfs(entry[1]);
@@ -430,10 +475,9 @@ var DirectedGraph = /** @class */ (function (_super) {
430
475
  return null;
431
476
  return sorted.reverse();
432
477
  };
433
- /**--- end find cycles --- */
434
478
  /**
435
- * The `edgeSet` function returns an array of all the edges in the graph.
436
- * @returns The `edgeSet()` method returns an array of edges (`E[]`).
479
+ * The `edgeSet` function returns an array of all directed edges in the graph.
480
+ * @returns The `edgeSet()` method returns an array of `E` objects.
437
481
  */
438
482
  DirectedGraph.prototype.edgeSet = function () {
439
483
  var edges = [];
@@ -442,22 +486,23 @@ var DirectedGraph = /** @class */ (function (_super) {
442
486
  });
443
487
  return edges;
444
488
  };
489
+ /**--- start find cycles --- */
445
490
  /**
446
- * The function `getNeighbors` returns an array of neighboring vertices for a given vertex or vertex ID.
447
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
448
- * (`VertexId`).
449
- * @returns an array of vertices (V[]).
491
+ * The function `getNeighbors` returns an array of neighboring vertices of a given vertex in a directed graph.
492
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a `V`
493
+ * object or a `VertexId`.
494
+ * @returns an array of DirectedVertex objects.
450
495
  */
451
496
  DirectedGraph.prototype.getNeighbors = function (vertexOrId) {
452
497
  var e_5, _a;
453
498
  var neighbors = [];
454
- var vertex = this.getVertex(vertexOrId);
499
+ var vertex = this._getVertex(vertexOrId);
455
500
  if (vertex) {
456
501
  var outEdges = this.outgoingEdgesOf(vertex);
457
502
  try {
458
503
  for (var outEdges_1 = __values(outEdges), outEdges_1_1 = outEdges_1.next(); !outEdges_1_1.done; outEdges_1_1 = outEdges_1.next()) {
459
504
  var outEdge = outEdges_1_1.value;
460
- var neighbor = this.getVertex(outEdge.dest);
505
+ var neighbor = this._getVertex(outEdge.dest);
461
506
  // TODO after no-non-null-assertion not ensure the logic
462
507
  if (neighbor) {
463
508
  neighbors.push(neighbor);
@@ -474,19 +519,20 @@ var DirectedGraph = /** @class */ (function (_super) {
474
519
  }
475
520
  return neighbors;
476
521
  };
522
+ /**--- end find cycles --- */
477
523
  /**
478
- * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
479
- * otherwise it returns null.
480
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
481
- * @returns an array containing two vertices [V, V] if the edge is found in the graph. If the edge is not found, it
482
- * returns null.
524
+ * The function "getEndsOfEdge" returns the source and destination vertices of a directed edge if it exists in the
525
+ * graph, otherwise it returns null.
526
+ * @param edge - A directed edge object with a generic type E.
527
+ * @returns an array containing the starting and ending vertices of the given directed edge, or null if the edge does
528
+ * not exist in the graph.
483
529
  */
484
530
  DirectedGraph.prototype.getEndsOfEdge = function (edge) {
485
531
  if (!this.hasEdge(edge.src, edge.dest)) {
486
532
  return null;
487
533
  }
488
- var v1 = this.getVertex(edge.src);
489
- var v2 = this.getVertex(edge.dest);
534
+ var v1 = this._getVertex(edge.src);
535
+ var v2 = this._getVertex(edge.dest);
490
536
  if (v1 && v2) {
491
537
  return [v1, v2];
492
538
  }
@@ -494,6 +540,12 @@ var DirectedGraph = /** @class */ (function (_super) {
494
540
  return null;
495
541
  }
496
542
  };
543
+ DirectedGraph.prototype._setOutEdgeMap = function (value) {
544
+ this._outEdgeMap = value;
545
+ };
546
+ DirectedGraph.prototype._setInEdgeMap = function (value) {
547
+ this._inEdgeMap = value;
548
+ };
497
549
  return DirectedGraph;
498
550
  }(abstract_graph_1.AbstractGraph));
499
551
  exports.DirectedGraph = DirectedGraph;