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
@@ -1,6 +1,13 @@
1
1
  import type { DijkstraResult, VertexId } from '../types';
2
2
  import { IAbstractGraph } from '../interfaces';
3
3
  export declare abstract class AbstractVertex<T = number> {
4
+ /**
5
+ * The function is a protected constructor that takes an id and an optional value as parameters.
6
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
7
+ * used to uniquely identify the vertex object.
8
+ * @param {T} [val] - The parameter "val" is an optional parameter of type T. It is used to assign a value to the
9
+ * vertex. If no value is provided, it will be set to undefined.
10
+ */
4
11
  protected constructor(id: VertexId, val?: T);
5
12
  private _id;
6
13
  get id(): VertexId;
@@ -10,6 +17,15 @@ export declare abstract class AbstractVertex<T = number> {
10
17
  set val(value: T | undefined);
11
18
  }
12
19
  export declare abstract class AbstractEdge<T = number> {
20
+ /**
21
+ * The above function is a protected constructor that initializes the weight, value, and hash code properties of an
22
+ * object.
23
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the object. If
24
+ * a value is provided, it will be assigned to the `_weight` property. If no value is provided, the default value of 1
25
+ * will be assigned.
26
+ * @param {T} [val] - The `val` parameter is of type `T`, which means it can be any type. It is an optional parameter,
27
+ * meaning it can be omitted when creating an instance of the class.
28
+ */
13
29
  protected constructor(weight?: number, val?: T);
14
30
  private _val;
15
31
  get val(): T | undefined;
@@ -19,6 +35,15 @@ export declare abstract class AbstractEdge<T = number> {
19
35
  set weight(v: number);
20
36
  protected _hashCode: string;
21
37
  get hashCode(): string;
38
+ /**
39
+ * 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.
40
+ * 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.
41
+ */
42
+ /**
43
+ * The function sets the value of the _hashCode property to the provided string.
44
+ * @param {string} v - The parameter "v" is of type string and represents the value that will be assigned to the
45
+ * "_hashCode" property.
46
+ */
22
47
  protected _setHashCode(v: string): void;
23
48
  }
24
49
  export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E extends AbstractEdge<any>> implements IAbstractGraph<V, E> {
@@ -41,22 +66,35 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
41
66
  */
42
67
  abstract createEdge(srcOrV1: VertexId | string, destOrV2: VertexId | string, weight?: number, val?: E): E;
43
68
  abstract removeEdge(edge: E): E | null;
69
+ abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
70
+ abstract degreeOf(vertexOrId: V | VertexId): number;
71
+ abstract edgeSet(): E[];
72
+ abstract edgesOf(vertexOrId: V | VertexId): E[];
73
+ abstract getNeighbors(vertexOrId: V | VertexId): V[];
74
+ abstract getEndsOfEdge(edge: E): [V, V] | null;
75
+ protected abstract _addEdgeOnly(edge: E): boolean;
76
+ /**
77
+ * The function "getVertex" returns the vertex with the specified ID or null if it doesn't exist.
78
+ * @param {VertexId} vertexId - The `vertexId` parameter is the identifier of the vertex that you want to retrieve from
79
+ * the `_vertices` map.
80
+ * @returns The method `getVertex` returns the vertex with the specified `vertexId` if it exists in the `_vertices`
81
+ * map. If the vertex does not exist, it returns `null`.
82
+ */
44
83
  getVertex(vertexId: VertexId): V | null;
45
84
  /**
46
85
  * The function checks if a vertex exists in a graph.
47
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
86
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
48
87
  * (`VertexId`).
49
- * @returns The method `hasVertex` returns a boolean value.
88
+ * @returns a boolean value.
50
89
  */
51
90
  hasVertex(vertexOrId: V | VertexId): boolean;
52
- abstract getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
53
- createAddVertex(id: VertexId, val?: V['val']): boolean;
54
- addVertex(newVertex: V): boolean;
91
+ addVertex(vertex: V): boolean;
92
+ addVertex(id: VertexId, val?: V['val']): boolean;
55
93
  /**
56
94
  * The `removeVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
57
95
  * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
58
96
  * (`VertexId`).
59
- * @returns The method `removeVertex` returns a boolean value.
97
+ * @returns The method is returning a boolean value.
60
98
  */
61
99
  removeVertex(vertexOrId: V | VertexId): boolean;
62
100
  /**
@@ -67,21 +105,17 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
67
105
  * were removed.
68
106
  */
69
107
  removeAllVertices(vertices: V[] | VertexId[]): boolean;
70
- abstract degreeOf(vertexOrId: V | VertexId): number;
71
- abstract edgeSet(): E[];
72
- abstract edgesOf(vertexOrId: V | VertexId): E[];
73
108
  /**
74
- * The function checks if there is an edge between two vertices in a graph.
75
- * @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the identifier of
76
- * a vertex in a graph, while V represents the type of the vertex itself.
77
- * @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in an edge. It can be either a `VertexId`
78
- * or a `V` type.
79
- * @returns The function `hasEdge` returns a boolean value. It returns `true` if there is an edge between the
80
- * vertices `v1` and `v2`, and `false` otherwise.
109
+ * The function checks if there is an edge between two vertices and returns a boolean value indicating the result.
110
+ * @param {VertexId | V} v1 - The parameter v1 can be either a VertexId or a V. A VertexId represents the unique
111
+ * identifier of a vertex in a graph, while V represents the type of the vertex object itself.
112
+ * @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in the edge. It can be either a
113
+ * `VertexId` or a `V` type, which represents the type of the vertex.
114
+ * @returns A boolean value is being returned.
81
115
  */
82
116
  hasEdge(v1: VertexId | V, v2: VertexId | V): boolean;
83
- createAddEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E['val']): boolean;
84
- abstract addEdge(edge: E): boolean;
117
+ addEdge(edge: E): boolean;
118
+ addEdge(src: V | VertexId, dest: V | VertexId, weight?: number, val?: E['val']): boolean;
85
119
  /**
86
120
  * The function sets the weight of an edge between two vertices in a graph.
87
121
  * @param {VertexId | V} srcOrId - The `srcOrId` parameter can be either a `VertexId` or a `V` object. It represents
@@ -94,15 +128,12 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
94
128
  * the weight of the edge and return true. If the edge does not exist, the function will return false.
95
129
  */
96
130
  setEdgeWeight(srcOrId: VertexId | V, destOrId: VertexId | V, weight: number): boolean;
97
- abstract getNeighbors(vertexOrId: V | VertexId): V[];
98
131
  /**
99
132
  * The function `getAllPathsBetween` finds all paths between two vertices in a graph using depth-first search.
100
133
  * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
101
134
  * It is the starting vertex for finding paths.
102
- * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
103
- * want to find paths to from the starting vertex `v1`.
104
- * @returns an array of arrays of vertices (V[][]). Each inner array represents a path between the given vertices (v1
105
- * and v2).
135
+ * @param {V | VertexId} v2 - The parameter `v2` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
136
+ * @returns The function `getAllPathsBetween` returns an array of arrays of vertices (`V[][]`).
106
137
  */
107
138
  getAllPathsBetween(v1: V | VertexId, v2: V | VertexId): V[][];
108
139
  /**
@@ -114,32 +145,37 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
114
145
  /**
115
146
  * The function `getMinCostBetween` calculates the minimum cost between two vertices in a graph, either based on edge
116
147
  * weights or using a breadth-first search algorithm.
117
- * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or vertex ID of the graph.
118
- * @param {V | VertexId} v2 - The parameter `v2` represents the second vertex in the graph. It can be either a vertex
119
- * object or a vertex ID.
148
+ * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
149
+ * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex to which
150
+ * you want to find the minimum cost or weight from the source vertex `v1`.
120
151
  * @param {boolean} [isWeight] - isWeight is an optional parameter that indicates whether the graph edges have weights.
121
152
  * If isWeight is set to true, the function will calculate the minimum cost between v1 and v2 based on the weights of
122
153
  * the edges. If isWeight is set to false or not provided, the function will calculate the
123
154
  * @returns The function `getMinCostBetween` returns a number representing the minimum cost between two vertices (`v1`
124
- * and `v2`) in a graph. If the `isWeight` parameter is `true`, it calculates the minimum weight between the vertices.
125
- * If `isWeight` is `false` or not provided, it calculates the minimum number of edges between the vertices. If the
126
- * vertices are not
155
+ * and `v2`). If the `isWeight` parameter is `true`, it calculates the minimum weight among all paths between the
156
+ * vertices. If `isWeight` is `false` or not provided, it uses a breadth-first search (BFS) algorithm to calculate the
157
+ * minimum number of
127
158
  */
128
159
  getMinCostBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): number | null;
129
160
  /**
130
161
  * The function `getMinPathBetween` returns the minimum path between two vertices in a graph, either based on weight or
131
162
  * using a breadth-first search algorithm.
132
- * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex or its ID.
133
- * @param {V | VertexId} v2 - The parameter `v2` represents the destination vertex or its ID. It is the vertex that we
134
- * want to find the minimum path to from the source vertex `v1`.
163
+ * @param {V | VertexId} v1 - The parameter `v1` represents the starting vertex of the path. It can be either a vertex
164
+ * object (`V`) or a vertex ID (`VertexId`).
165
+ * @param {V | VertexId} v2 - V | VertexId - The second vertex or vertex ID between which we want to find the minimum
166
+ * path.
135
167
  * @param {boolean} [isWeight] - A boolean flag indicating whether to consider the weight of edges in finding the
136
168
  * minimum path. If set to true, the function will use Dijkstra's algorithm to find the minimum weighted path. If set
137
- * to false, the function will use breadth-first search (BFS) to find the minimum path. If
169
+ * to false, the function will use breadth-first search (BFS) to find the minimum path.
138
170
  * @returns The function `getMinPathBetween` returns an array of vertices (`V[]`) representing the minimum path between
139
- * two vertices (`v1` and `v2`). If no path is found, it returns `null`.
171
+ * two vertices (`v1` and `v2`). If there is no path between the vertices, it returns `null`.
140
172
  */
141
173
  getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
142
174
  /**
175
+ * Dijkstra algorithm time: O(VE) space: O(V + E)
176
+ * /
177
+
178
+ /**
143
179
  * Dijkstra algorithm time: O(VE) space: O(V + E)
144
180
  * The function `dijkstraWithoutHeap` implements Dijkstra's algorithm to find the shortest path between two vertices in
145
181
  * a graph without using a heap data structure.
@@ -159,6 +195,14 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
159
195
  dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
160
196
  /**
161
197
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
198
+ *
199
+ * 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.
200
+ * 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.
201
+ * 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.
202
+ *
203
+ * /
204
+
205
+ /**
162
206
  * 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.
163
207
  * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
164
208
  * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
@@ -177,11 +221,30 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
177
221
  */
178
222
  dijkstra(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
179
223
  /**
224
+ * Dijkstra algorithm time: O(logVE) space: O(V + E)
225
+ * /
226
+
227
+ /**
180
228
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
181
229
  * 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.
182
230
  */
183
- abstract getEndsOfEdge(edge: E): [V, V] | null;
184
231
  /**
232
+ * BellmanFord time:O(VE) space:O(V)
233
+ * one to rest pairs
234
+ * 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.
235
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
236
+ */
237
+ /**
238
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
239
+ * all pairs
240
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
241
+ */
242
+ /**
243
+ * BellmanFord time:O(VE) space:O(V)
244
+ * one to rest pairs
245
+ * /
246
+
247
+ /**
185
248
  * BellmanFord time:O(VE) space:O(V)
186
249
  * one to rest pairs
187
250
  * 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.
@@ -206,11 +269,11 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
206
269
  minPath: V[];
207
270
  };
208
271
  /**
209
- * 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.
210
- * 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.
211
- * 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.
212
- */
213
- /**
272
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
273
+ * all pairs
274
+ * /
275
+
276
+ /**
214
277
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
215
278
  * all pairs
216
279
  * 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.
@@ -226,6 +289,14 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
226
289
  predecessor: (V | null)[][];
227
290
  };
228
291
  /**
292
+ * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
293
+ * Tarjan can find cycles in directed or undirected graph
294
+ * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
295
+ * Tarjan solve the bi-connected components of undirected graphs;
296
+ * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
297
+ * /
298
+
299
+ /**
229
300
  * Tarjan is an algorithm based on DFS,which is used to solve the connectivity problem of graphs.
230
301
  * Tarjan can find cycles in directed or undirected graph
231
302
  * Tarjan can find the articulation points and bridges(critical edges) of undirected graphs in linear time,
@@ -254,19 +325,8 @@ export declare abstract class AbstractGraph<V extends AbstractVertex<any>, E ext
254
325
  SCCs: Map<number, V[]>;
255
326
  cycles: Map<number, V[]>;
256
327
  };
257
- /**
258
- * BellmanFord time:O(VE) space:O(V)
259
- * one to rest pairs
260
- * 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.
261
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
262
- */
328
+ protected _addVertexOnly(newVertex: V): boolean;
263
329
  protected _getVertex(vertexOrId: VertexId | V): V | null;
264
- /**
265
- * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
266
- * all pairs
267
- * 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.
268
- */
269
330
  protected _getVertexId(vertexOrId: V | VertexId): VertexId;
270
- /**--- start find cycles --- */
271
331
  protected _setVertices(value: Map<VertexId, V>): void;
272
332
  }