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
@@ -47,6 +47,13 @@ exports.AbstractGraph = exports.AbstractEdge = exports.AbstractVertex = void 0;
47
47
  var utils_1 = require("../../utils");
48
48
  var priority_queue_1 = require("../priority-queue");
49
49
  var AbstractVertex = /** @class */ (function () {
50
+ /**
51
+ * The function is a protected constructor that takes an id and an optional value as parameters.
52
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
53
+ * used to uniquely identify the vertex object.
54
+ * @param {T} [val] - The parameter "val" is an optional parameter of type T. It is used to assign a value to the
55
+ * vertex. If no value is provided, it will be set to undefined.
56
+ */
50
57
  function AbstractVertex(id, val) {
51
58
  this._id = id;
52
59
  this._val = val;
@@ -75,6 +82,15 @@ var AbstractVertex = /** @class */ (function () {
75
82
  }());
76
83
  exports.AbstractVertex = AbstractVertex;
77
84
  var AbstractEdge = /** @class */ (function () {
85
+ /**
86
+ * The above function is a protected constructor that initializes the weight, value, and hash code properties of an
87
+ * object.
88
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
89
+ * a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
90
+ * will be assigned.
91
+ * @param {T} [val] - The `val` parameter is of type `T`, which means it can be any type. It is an optional parameter,
92
+ * meaning it can be omitted when creating an instance of the class.
93
+ */
78
94
  function AbstractEdge(weight, val) {
79
95
  this._weight = weight !== undefined ? weight : 1;
80
96
  this._val = val;
@@ -107,28 +123,24 @@ var AbstractEdge = /** @class */ (function () {
107
123
  enumerable: false,
108
124
  configurable: true
109
125
  });
110
- // /**
111
- // * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
112
- // * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
113
- // * @param srcOrV1
114
- // * @param destOrV2
115
- // * @param weight
116
- // * @param val
117
- // */
118
- // abstract createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
126
+ /**
127
+ * 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.
128
+ * 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.
129
+ */
130
+ /**
131
+ * The function sets the value of the _hashCode property to the provided string.
132
+ * @param {string} v - The parameter "v" is of type string and represents the value that will be assigned to the
133
+ * "_hashCode" property.
134
+ */
119
135
  AbstractEdge.prototype._setHashCode = function (v) {
120
136
  this._hashCode = v;
121
137
  };
122
138
  return AbstractEdge;
123
139
  }());
124
140
  exports.AbstractEdge = AbstractEdge;
125
- // Connected Component === Largest Connected Sub-Graph
126
141
  var AbstractGraph = /** @class */ (function () {
127
142
  function AbstractGraph() {
128
143
  this._vertices = new Map();
129
- // unionFind() {}
130
- /**--- end find cycles --- */
131
- // Minimum Spanning Tree
132
144
  }
133
145
  Object.defineProperty(AbstractGraph.prototype, "vertices", {
134
146
  get: function () {
@@ -137,35 +149,39 @@ var AbstractGraph = /** @class */ (function () {
137
149
  enumerable: false,
138
150
  configurable: true
139
151
  });
152
+ /**
153
+ * The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
154
+ * @param {VertexId} vertexId - The `vertexId` parameter is the identifier of the vertex that you want to retrieve from
155
+ * the `_vertices` map.
156
+ * @returns The method `getVertex` returns the vertex with the specified `vertexId` if it exists in the `_vertices`
157
+ * map. If the vertex does not exist, it returns `null`.
158
+ */
140
159
  AbstractGraph.prototype.getVertex = function (vertexId) {
141
160
  return this._vertices.get(vertexId) || null;
142
161
  };
143
162
  /**
144
163
  * The function checks if a vertex exists in a graph.
145
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
164
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
146
165
  * (`VertexId`).
147
- * @returns The method `hasVertex` returns a boolean value.
166
+ * @returns a boolean value.
148
167
  */
149
168
  AbstractGraph.prototype.hasVertex = function (vertexOrId) {
150
169
  return this._vertices.has(this._getVertexId(vertexOrId));
151
170
  };
152
- AbstractGraph.prototype.createAddVertex = function (id, val) {
153
- var newVertex = this.createVertex(id, val);
154
- return this.addVertex(newVertex);
155
- };
156
- AbstractGraph.prototype.addVertex = function (newVertex) {
157
- if (this.hasVertex(newVertex)) {
158
- return false;
159
- // throw (new Error('Duplicated vertex id is not allowed'));
171
+ AbstractGraph.prototype.addVertex = function (idOrVertex, val) {
172
+ if (idOrVertex instanceof AbstractVertex) {
173
+ return this._addVertexOnly(idOrVertex);
174
+ }
175
+ else {
176
+ var newVertex = this.createVertex(idOrVertex, val);
177
+ return this._addVertexOnly(newVertex);
160
178
  }
161
- this._vertices.set(newVertex.id, newVertex);
162
- return true;
163
179
  };
164
180
  /**
165
181
  * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
166
182
  * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
167
183
  * (`VertexId`).
168
- * @returns The method `removeVertex` returns a boolean value.
184
+ * @returns The method is returning a boolean value.
169
185
  */
170
186
  AbstractGraph.prototype.removeVertex = function (vertexOrId) {
171
187
  var vertexId = this._getVertexId(vertexOrId);
@@ -197,25 +213,36 @@ var AbstractGraph = /** @class */ (function () {
197
213
  return removed.length > 0;
198
214
  };
199
215
  /**
200
- * The function checks if there is an edge between two vertices in a graph.
201
- * @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the identifier of
202
- * a vertex in a graph, while V represents the type of the vertex itself.
203
- * @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in an edge. It can be either a `VertexId`
204
- * or a `V` type.
205
- * @returns The function `hasEdge` returns a boolean value. It returns `true` if there is an edge between the
206
- * vertices `v1` and `v2`, and `false` otherwise.
216
+ * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
217
+ * @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the unique
218
+ * identifier of a vertex in a graph, while V represents the type of the vertex object itself.
219
+ * @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
220
+ * `VertexId` or a `V` type, which represents the type of the vertex.
221
+ * @returns A boolean value is being returned.
207
222
  */
208
223
  AbstractGraph.prototype.hasEdge = function (v1, v2) {
209
224
  var edge = this.getEdge(v1, v2);
210
225
  return !!edge;
211
226
  };
212
- AbstractGraph.prototype.createAddEdge = function (src, dest, weight, val) {
213
- if (src instanceof AbstractVertex)
214
- src = src.id;
215
- if (dest instanceof AbstractVertex)
216
- dest = dest.id;
217
- var newEdge = this.createEdge(src, dest, weight, val);
218
- return this.addEdge(newEdge);
227
+ AbstractGraph.prototype.addEdge = function (srcOrEdge, dest, weight, val) {
228
+ if (srcOrEdge instanceof AbstractEdge) {
229
+ return this._addEdgeOnly(srcOrEdge);
230
+ }
231
+ else {
232
+ if (dest instanceof AbstractVertex || typeof dest === 'string' || typeof dest === 'number') {
233
+ if (!(this.hasVertex(srcOrEdge) && this.hasVertex(dest)))
234
+ return false;
235
+ if (srcOrEdge instanceof AbstractVertex)
236
+ srcOrEdge = srcOrEdge.id;
237
+ if (dest instanceof AbstractVertex)
238
+ dest = dest.id;
239
+ var newEdge = this.createEdge(srcOrEdge, dest, weight, val);
240
+ return this._addEdgeOnly(newEdge);
241
+ }
242
+ else {
243
+ throw new Error('dest must be a Vertex or vertex id while srcOrEdge is an Edge');
244
+ }
245
+ }
219
246
  };
220
247
  /**
221
248
  * The function sets the weight of an edge between two vertices in a graph.
@@ -242,10 +269,8 @@ var AbstractGraph = /** @class */ (function () {
242
269
  * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
243
270
  * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
244
271
  * It is the starting vertex for finding paths.
245
- * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
246
- * want to find paths to from the starting vertex `v1`.
247
- * @returns an array of arrays of vertices (V[][]). Each inner array represents a path between the given vertices (v1
248
- * and v2).
272
+ * @param {V | VertexId} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
273
+ * @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).
249
274
  */
250
275
  AbstractGraph.prototype.getAllPathsBetween = function (v1, v2) {
251
276
  var _this = this;
@@ -303,16 +328,16 @@ var AbstractGraph = /** @class */ (function () {
303
328
  /**
304
329
  * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
305
330
  * weights or using a breadth-first search algorithm.
306
- * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or vertex ID of the graph.
307
- * @param {V | VertexId} v2 - The parameter `v2` represents the second vertex in the graph. It can be either a vertex
308
- * object or a vertex ID.
331
+ * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
332
+ * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
333
+ * you want to find the minimum cost or weight from the source vertex `v1`.
309
334
  * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
310
335
  * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
311
336
  * the edges. If isWeight is set to false or not provided, the function will calculate the
312
337
  * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertices (`v1`
313
- * and `v2`) in a graph. If the `isWeight` parameter is `true`, it calculates the minimum weight between the vertices.
314
- * If `isWeight` is `false` or not provided, it calculates the minimum number of edges between the vertices. If the
315
- * vertices are not
338
+ * and `v2`). If the `isWeight` parameter is `true`, it calculates the minimum weight among all paths between the
339
+ * vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
340
+ * minimum number of
316
341
  */
317
342
  AbstractGraph.prototype.getMinCostBetween = function (v1, v2, isWeight) {
318
343
  var e_3, _a, e_4, _b;
@@ -382,14 +407,15 @@ var AbstractGraph = /** @class */ (function () {
382
407
  /**
383
408
  * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
384
409
  * using a breadth-first search algorithm.
385
- * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
386
- * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
387
- * want to find the minimum path to from the source vertex `v1`.
410
+ * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
411
+ * object (`V`) or a vertex ID (`VertexId`).
412
+ * @param {V | VertexId} v2 - V | VertexId - The second vertex or vertex ID between which we want to find the minimum
413
+ * path.
388
414
  * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
389
415
  * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
390
- * to false, the function will use breadth-first search (BFS) to find the minimum path. If
416
+ * to false, the function will use breadth-first search (BFS) to find the minimum path.
391
417
  * @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
392
- * two vertices (`v1` and `v2`). If no path is found, it returns `null`.
418
+ * two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `null`.
393
419
  */
394
420
  AbstractGraph.prototype.getMinPathBetween = function (v1, v2, isWeight) {
395
421
  var e_5, _a;
@@ -464,6 +490,10 @@ var AbstractGraph = /** @class */ (function () {
464
490
  }
465
491
  };
466
492
  /**
493
+ * Dijkstra algorithm time: O(VE) space: O(V + E)
494
+ * /
495
+
496
+ /**
467
497
  * Dijkstra algorithm time: O(VE) space: O(V + E)
468
498
  * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
469
499
  * a graph without using a heap data structure.
@@ -626,6 +656,14 @@ var AbstractGraph = /** @class */ (function () {
626
656
  };
627
657
  /**
628
658
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
659
+ *
660
+ * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
661
+ * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
662
+ * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
663
+ *
664
+ * /
665
+
666
+ /**
629
667
  * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
630
668
  * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
631
669
  * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
@@ -772,7 +810,31 @@ var AbstractGraph = /** @class */ (function () {
772
810
  }
773
811
  return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
774
812
  };
813
+ /**
814
+ * Dijkstra algorithm time: O(logVE) space: O(V + E)
815
+ * /
816
+
817
+ /**
818
+ * Dijkstra algorithm time: O(logVE) space: O(V + E)
819
+ * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
820
+ */
821
+ /**
822
+ * BellmanFord time:O(VE) space:O(V)
823
+ * one to rest pairs
824
+ * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
825
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
826
+ */
827
+ /**
828
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
829
+ * all pairs
830
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
831
+ */
775
832
  /**
833
+ * BellmanFord time:O(VE) space:O(V)
834
+ * one to rest pairs
835
+ * /
836
+
837
+ /**
776
838
  * BellmanFord time:O(VE) space:O(V)
777
839
  * one to rest pairs
778
840
  * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
@@ -885,11 +947,11 @@ var AbstractGraph = /** @class */ (function () {
885
947
  return { hasNegativeCycle: hasNegativeCycle, distMap: distMap, preMap: preMap, paths: paths, min: min, minPath: minPath };
886
948
  };
887
949
  /**
888
- * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
889
- * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
890
- * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
891
- */
892
- /**
950
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
951
+ * all pairs
952
+ * /
953
+
954
+ /**
893
955
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
894
956
  * all pairs
895
957
  * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
@@ -932,6 +994,14 @@ var AbstractGraph = /** @class */ (function () {
932
994
  return { costs: costs, predecessor: predecessor };
933
995
  };
934
996
  /**
997
+ * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
998
+ * Tarjan can find cycles in directed or undirected graph
999
+ * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
1000
+ * Tarjan solve the bi-connected components of undirected graphs;
1001
+ * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
1002
+ * /
1003
+
1004
+ /**
935
1005
  * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
936
1006
  * Tarjan can find cycles in directed or undirected graph
937
1007
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
@@ -1058,25 +1128,21 @@ var AbstractGraph = /** @class */ (function () {
1058
1128
  }
1059
1129
  return { dfnMap: dfnMap, lowMap: lowMap, bridges: bridges, articulationPoints: articulationPoints, SCCs: SCCs, cycles: cycles };
1060
1130
  };
1061
- /**
1062
- * BellmanFord time:O(VE) space:O(V)
1063
- * one to rest pairs
1064
- * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
1065
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
1066
- */
1131
+ AbstractGraph.prototype._addVertexOnly = function (newVertex) {
1132
+ if (this.hasVertex(newVertex)) {
1133
+ return false;
1134
+ // throw (new Error('Duplicated vertex id is not allowed'));
1135
+ }
1136
+ this._vertices.set(newVertex.id, newVertex);
1137
+ return true;
1138
+ };
1067
1139
  AbstractGraph.prototype._getVertex = function (vertexOrId) {
1068
1140
  var vertexId = this._getVertexId(vertexOrId);
1069
1141
  return this._vertices.get(vertexId) || null;
1070
1142
  };
1071
- /**
1072
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
1073
- * all pairs
1074
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
1075
- */
1076
1143
  AbstractGraph.prototype._getVertexId = function (vertexOrId) {
1077
1144
  return vertexOrId instanceof AbstractVertex ? vertexOrId.id : vertexOrId;
1078
1145
  };
1079
- /**--- start find cycles --- */
1080
1146
  AbstractGraph.prototype._setVertices = function (value) {
1081
1147
  this._vertices = value;
1082
1148
  };