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
@@ -1,106 +1,129 @@
1
1
  import { AbstractEdge, AbstractGraph, AbstractVertex } from './abstract-graph';
2
2
  import type { VertexId } from '../types';
3
- export declare class UndirectedVertex extends AbstractVertex {
3
+ export declare class UndirectedVertex<T = number> extends AbstractVertex<T> {
4
4
  /**
5
- * The constructor function initializes an object with a given id.
6
- * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is used to uniquely identify the
7
- * vertex within a graph or network.
5
+ * The constructor function initializes a vertex with an optional value.
6
+ * @param {VertexId} id - The `id` parameter is the identifier for the vertex. It is of type `VertexId`, which is
7
+ * typically a unique identifier for each vertex in a graph.
8
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
9
+ * vertex. If no value is provided, the vertex will be initialized with a default value.
8
10
  */
9
- constructor(id: VertexId);
11
+ constructor(id: VertexId, val?: T);
10
12
  }
11
- export declare class UndirectedEdge extends AbstractEdge {
13
+ export declare class UndirectedEdge<T = number> extends AbstractEdge<T> {
12
14
  /**
13
- * The constructor function initializes an instance of a class with two vertex IDs and an optional weight.
15
+ * The constructor function initializes an instance of a class with two vertex IDs, an optional weight, and an optional
16
+ * value.
14
17
  * @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
15
18
  * @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
16
- * graph.
17
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
18
- * between two vertices.
19
+ * graph edge.
20
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
21
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
22
+ * the edge.
19
23
  */
20
- constructor(v1: VertexId, v2: VertexId, weight?: number);
24
+ constructor(v1: VertexId, v2: VertexId, weight?: number, val?: T);
21
25
  private _vertices;
22
26
  get vertices(): [VertexId, VertexId];
23
27
  set vertices(v: [VertexId, VertexId]);
24
- /**
25
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
26
- */
27
- getVertices(): [VertexId, VertexId];
28
28
  }
29
- export declare class UndirectedGraph<V extends UndirectedVertex, E extends UndirectedEdge> extends AbstractGraph<V, E> {
30
- constructor();
29
+ export declare class UndirectedGraph<V extends UndirectedVertex<any>, E extends UndirectedEdge<any>> extends AbstractGraph<V, E> {
30
+ private readonly _vertexConstructor;
31
+ private readonly _edgeConstructor;
32
+ constructor(vertexConstructor: new (id: VertexId, val?: V['val']) => V, edgeConstructor: new (src: VertexId, dest: VertexId, weight?: number, val?: E['val']) => E);
31
33
  protected _edges: Map<V, E[]>;
32
34
  get edges(): Map<V, E[]>;
33
35
  /**
34
- * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
35
- * @param {V | null | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID
36
- * (`VertexId`). It can also be `null`.
37
- * @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
38
- * object), `null`, or `VertexId` (vertex ID).
39
- * @returns an edge (E) or null.
36
+ * 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.
37
+ * 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.
38
+ * @param id
39
+ * @param val
40
+ */
41
+ _createVertex(id: VertexId, val?: V['val']): V;
42
+ /**
43
+ * 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.
44
+ * 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.
45
+ * @param src
46
+ * @param dest
47
+ * @param weight
48
+ * @param val
49
+ */
50
+ _createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
51
+ /**
52
+ * The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
53
+ * exists.
54
+ * @param {V | null | VertexId} v1 - The parameter `v1` represents either an `V`
55
+ * object, `null`, or a `VertexId`. It is used to specify one of the vertices of the edge.
56
+ * @param {V | null | VertexId} v2 - The parameter `v2` represents either an `UndirectedVertex`
57
+ * object or a `VertexId` (identifier) of an undirected vertex.
58
+ * @returns an instance of `E` or `null`.
40
59
  */
41
60
  getEdge(v1: V | null | VertexId, v2: V | null | VertexId): E | null;
42
61
  /**
43
- * The function adds an edge to a graph by connecting two vertices.
44
- * @param {E} edge - The `edge` parameter is an object of type `E`, which represents an edge in a graph.
62
+ * The function adds an undirected edge to a graph by updating the adjacency list.
63
+ * @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
64
+ * array of two vertices connected by the edge.
45
65
  * @returns a boolean value.
46
66
  */
47
67
  addEdge(edge: E): boolean;
48
68
  /**
49
- * The function removes an edge between two vertices in a graph and returns the removed edge, or null if either of the
50
- * vertices does not exist.
51
- * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
52
- * @param {V | VertexId} v2 - V | VertexId: The second vertex or vertex ID of the edge to be removed.
53
- * @returns the removed edge (E) if it exists, or null if either of the vertices (v1 or v2) does not exist.
69
+ * The function removes an edge between two vertices in an undirected graph.
70
+ * @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
71
+ * a `VertexId`. It is used to specify one of the vertices of the edge that needs to be removed.
72
+ * @param {V | VertexId} v2 - The parameter `v2` represents either an instance of the
73
+ * `UndirectedVertex` class or a `VertexId`. It is used to identify the second vertex of the edge that needs to be
74
+ * removed.
75
+ * @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
76
+ * between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
77
+ * between them, the function returns `null`.
54
78
  */
55
79
  removeEdgeBetween(v1: V | VertexId, v2: V | VertexId): E | null;
56
80
  /**
57
- * The removeEdge function removes an edge between two vertices in a graph.
58
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
59
- * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
81
+ * The removeEdge function removes an edge between two vertices in an undirected graph.
82
+ * @param edge - An object representing an undirected edge. It has a property called "vertices" which is an array
83
+ * containing the two vertices connected by the edge.
84
+ * @returns The method is returning an UndirectedEdge object or null.
60
85
  */
61
86
  removeEdge(edge: E): E | null;
62
87
  /**
63
- * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
64
- * vertex.
65
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
66
- * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
67
- * edges that are incident to that vertex.
88
+ * The function "degreeOf" returns the degree of a given vertex in an undirected graph.
89
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
90
+ * `V`.
91
+ * @returns the degree of the vertex.
68
92
  */
69
93
  degreeOf(vertexOrId: VertexId | V): number;
70
94
  /**
71
- * The function "edgesOf" returns an array of edges connected to a given vertex.
72
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
73
- * @returns an array of edges connected to the specified vertex. If the vertex exists in the graph, the function
74
- * returns the array of edges connected to that vertex. If the vertex does not exist in the graph, the function returns
75
- * an empty array.
95
+ * The function "edgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
96
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
97
+ * `V`.
98
+ * @returns an array of UndirectedEdge objects.
76
99
  */
77
100
  edgesOf(vertexOrId: VertexId | V): E[];
78
101
  /**
79
- * The function "edgeSet" returns an array of unique edges from a set of edges.
80
- * @returns The method `edgeSet()` returns an array of type `E[]`.
102
+ * The function "edgeSet" returns an array of unique undirected edges from a set of edges.
103
+ * @returns The method `edgeSet()` returns an array of `E` objects.
81
104
  */
82
105
  edgeSet(): E[];
83
106
  /**
84
- * The function "getEdgesOf" returns an array of edges connected to a given vertex or vertex ID.
85
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
86
- * (`VertexId`).
87
- * @returns an array of edges (E[]) that are connected to the specified vertex or vertex ID.
107
+ * The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
108
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
109
+ * `V` object or a `VertexId`.
110
+ * @returns The function `getEdgesOf` returns an array of `E` objects.
88
111
  */
89
112
  getEdgesOf(vertexOrId: V | VertexId): E[];
90
113
  /**
91
- * The function "getNeighbors" returns an array of neighboring vertices of a given vertex.
92
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
93
- * (`VertexId`).
94
- * @returns an array of vertices (V[]).
114
+ * The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
115
+ * @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
116
+ * `V` object or a `VertexId`. It represents the vertex for which we want to find the neighbors.
117
+ * @returns an array of UndirectedVertex objects.
95
118
  */
96
119
  getNeighbors(vertexOrId: V | VertexId): V[];
97
120
  /**
98
- * The function "getEndsOfEdge" returns the vertices at the ends of a given edge, or null if the edge does not exist in
99
- * the graph.
100
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
101
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
102
- * graph and both vertices are found. If the edge does not exist or one or both vertices are not found, it returns
103
- * `null`.
121
+ * The function "getEndsOfEdge" returns the two vertices that form the ends of a given undirected edge, or null if the
122
+ * edge does not exist in the graph.
123
+ * @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
124
+ * array containing two vertices that the edge connects.
125
+ * @returns The function `getEndsOfEdge` returns an array containing the two ends of the given `edge` if the edge
126
+ * exists in the graph. If the edge does not exist, it returns `null`.
104
127
  */
105
128
  getEndsOfEdge(edge: E): [V, V] | null;
106
129
  protected _setEdges(v: Map<V, E[]>): void;
@@ -64,12 +64,14 @@ var abstract_graph_1 = require("./abstract-graph");
64
64
  var UndirectedVertex = /** @class */ (function (_super) {
65
65
  __extends(UndirectedVertex, _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 initialize the value of the
71
+ * vertex. If no value is provided, the vertex will be initialized with a default value.
70
72
  */
71
- function UndirectedVertex(id) {
72
- return _super.call(this, id) || this;
73
+ function UndirectedVertex(id, val) {
74
+ return _super.call(this, id, val) || this;
73
75
  }
74
76
  return UndirectedVertex;
75
77
  }(abstract_graph_1.AbstractVertex));
@@ -77,15 +79,17 @@ exports.UndirectedVertex = UndirectedVertex;
77
79
  var UndirectedEdge = /** @class */ (function (_super) {
78
80
  __extends(UndirectedEdge, _super);
79
81
  /**
80
- * The constructor function initializes an instance of a class with two vertex IDs and an optional weight.
82
+ * The constructor function initializes an instance of a class with two vertex IDs, an optional weight, and an optional
83
+ * value.
81
84
  * @param {VertexId} v1 - The parameter `v1` is of type `VertexId` and represents the first vertex in the edge.
82
85
  * @param {VertexId} v2 - The parameter `v2` is a `VertexId`, which represents the identifier of the second vertex in a
83
- * graph.
84
- * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge
85
- * between two vertices.
86
+ * graph edge.
87
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
88
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It represents the value associated with
89
+ * the edge.
86
90
  */
87
- function UndirectedEdge(v1, v2, weight) {
88
- var _this = _super.call(this, weight) || this;
91
+ function UndirectedEdge(v1, v2, weight, val) {
92
+ var _this = _super.call(this, weight, val) || this;
89
93
  _this._vertices = [v1, v2];
90
94
  return _this;
91
95
  }
@@ -99,19 +103,15 @@ var UndirectedEdge = /** @class */ (function (_super) {
99
103
  enumerable: false,
100
104
  configurable: true
101
105
  });
102
- /**
103
- * Starting from TypeScript version 5.0 and onwards, the use of distinct access modifiers for Getters and Setters is not permitted. As an alternative, to ensure compatibility, it is necessary to adopt a Java-style approach for Setters (using the same name as the property) while utilizing separate method names for Getters.
104
- */
105
- UndirectedEdge.prototype.getVertices = function () {
106
- return this._vertices;
107
- };
108
106
  return UndirectedEdge;
109
107
  }(abstract_graph_1.AbstractEdge));
110
108
  exports.UndirectedEdge = UndirectedEdge;
111
109
  var UndirectedGraph = /** @class */ (function (_super) {
112
110
  __extends(UndirectedGraph, _super);
113
- function UndirectedGraph() {
111
+ function UndirectedGraph(vertexConstructor, edgeConstructor) {
114
112
  var _this = _super.call(this) || this;
113
+ _this._vertexConstructor = vertexConstructor;
114
+ _this._edgeConstructor = edgeConstructor;
115
115
  _this._edges = new Map();
116
116
  return _this;
117
117
  }
@@ -123,19 +123,42 @@ var UndirectedGraph = /** @class */ (function (_super) {
123
123
  configurable: true
124
124
  });
125
125
  /**
126
- * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.
127
- * @param {V | null | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID
128
- * (`VertexId`). It can also be `null`.
129
- * @param {V | null | VertexId} v2 - The parameter `v2` represents a vertex or vertex ID. It can be of type `V` (vertex
130
- * object), `null`, or `VertexId` (vertex ID).
131
- * @returns an edge (E) or null.
126
+ * 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.
127
+ * 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.
128
+ * @param id
129
+ * @param val
130
+ */
131
+ UndirectedGraph.prototype._createVertex = function (id, val) {
132
+ return new this._vertexConstructor(id, val);
133
+ };
134
+ /**
135
+ * 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.
136
+ * 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.
137
+ * @param src
138
+ * @param dest
139
+ * @param weight
140
+ * @param val
141
+ */
142
+ UndirectedGraph.prototype._createEdge = function (src, dest, weight, val) {
143
+ if (weight === undefined || weight === null)
144
+ weight = 1;
145
+ return new this._edgeConstructor(src, dest, weight, val);
146
+ };
147
+ /**
148
+ * The function `getEdge` returns the first undirected edge that connects two given vertices, or null if no such edge
149
+ * exists.
150
+ * @param {V | null | VertexId} v1 - The parameter `v1` represents either an `V`
151
+ * object, `null`, or a `VertexId`. It is used to specify one of the vertices of the edge.
152
+ * @param {V | null | VertexId} v2 - The parameter `v2` represents either an `UndirectedVertex`
153
+ * object or a `VertexId` (identifier) of an undirected vertex.
154
+ * @returns an instance of `E` or `null`.
132
155
  */
133
156
  UndirectedGraph.prototype.getEdge = function (v1, v2) {
134
157
  var _a;
135
158
  var edges = [];
136
159
  if (v1 !== null && v2 !== null) {
137
- var vertex1 = this.getVertex(v1);
138
- var vertex2_1 = this.getVertex(v2);
160
+ var vertex1 = this._getVertex(v1);
161
+ var vertex2_1 = this._getVertex(v2);
139
162
  if (vertex1 && vertex2_1) {
140
163
  edges = (_a = this._edges.get(vertex1)) === null || _a === void 0 ? void 0 : _a.filter(function (e) { return e.vertices.includes(vertex2_1.id); });
141
164
  }
@@ -143,8 +166,9 @@ var UndirectedGraph = /** @class */ (function (_super) {
143
166
  return edges ? edges[0] || null : null;
144
167
  };
145
168
  /**
146
- * The function adds an edge to a graph by connecting two vertices.
147
- * @param {E} edge - The `edge` parameter is an object of type `E`, which represents an edge in a graph.
169
+ * The function adds an undirected edge to a graph by updating the adjacency list.
170
+ * @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
171
+ * array of two vertices connected by the edge.
148
172
  * @returns a boolean value.
149
173
  */
150
174
  UndirectedGraph.prototype.addEdge = function (edge) {
@@ -152,7 +176,7 @@ var UndirectedGraph = /** @class */ (function (_super) {
152
176
  try {
153
177
  for (var _b = __values(edge.vertices), _c = _b.next(); !_c.done; _c = _b.next()) {
154
178
  var end = _c.value;
155
- var endVertex = this.getVertex(end);
179
+ var endVertex = this._getVertex(end);
156
180
  if (endVertex === null)
157
181
  return false;
158
182
  if (endVertex) {
@@ -176,15 +200,19 @@ var UndirectedGraph = /** @class */ (function (_super) {
176
200
  return true;
177
201
  };
178
202
  /**
179
- * The function removes an edge between two vertices in a graph and returns the removed edge, or null if either of the
180
- * vertices does not exist.
181
- * @param {V | VertexId} v1 - The parameter `v1` represents either a vertex object (`V`) or a vertex ID (`VertexId`).
182
- * @param {V | VertexId} v2 - V | VertexId: The second vertex or vertex ID of the edge to be removed.
183
- * @returns the removed edge (E) if it exists, or null if either of the vertices (v1 or v2) does not exist.
203
+ * The function removes an edge between two vertices in an undirected graph.
204
+ * @param {V | VertexId} v1 - The parameter `v1` represents either an `V` object or
205
+ * a `VertexId`. It is used to specify one of the vertices of the edge that needs to be removed.
206
+ * @param {V | VertexId} v2 - The parameter `v2` represents either an instance of the
207
+ * `UndirectedVertex` class or a `VertexId`. It is used to identify the second vertex of the edge that needs to be
208
+ * removed.
209
+ * @returns The function `removeEdgeBetween` returns an `E` object if an edge is successfully removed
210
+ * between the two vertices `v1` and `v2`. If either `v1` or `v2` is not found in the graph, or if there is no edge
211
+ * between them, the function returns `null`.
184
212
  */
185
213
  UndirectedGraph.prototype.removeEdgeBetween = function (v1, v2) {
186
- var vertex1 = this.getVertex(v1);
187
- var vertex2 = this.getVertex(v2);
214
+ var vertex1 = this._getVertex(v1);
215
+ var vertex2 = this._getVertex(v2);
188
216
  if (!vertex1 || !vertex2) {
189
217
  return null;
190
218
  }
@@ -200,23 +228,23 @@ var UndirectedGraph = /** @class */ (function (_super) {
200
228
  return removed;
201
229
  };
202
230
  /**
203
- * The removeEdge function removes an edge between two vertices in a graph.
204
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
205
- * @returns The method is returning either the removed edge (of type E) or null if the edge was not found.
231
+ * The removeEdge function removes an edge between two vertices in an undirected graph.
232
+ * @param edge - An object representing an undirected edge. It has a property called "vertices" which is an array
233
+ * containing the two vertices connected by the edge.
234
+ * @returns The method is returning an UndirectedEdge object or null.
206
235
  */
207
236
  UndirectedGraph.prototype.removeEdge = function (edge) {
208
237
  return this.removeEdgeBetween(edge.vertices[0], edge.vertices[1]);
209
238
  };
210
239
  /**
211
- * The function `degreeOf` returns the degree of a vertex in a graph, which is the number of edges connected to that
212
- * vertex.
213
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
214
- * @returns The function `degreeOf` returns the degree of a vertex in a graph. The degree of a vertex is the number of
215
- * edges that are incident to that vertex.
240
+ * The function "degreeOf" returns the degree of a given vertex in an undirected graph.
241
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
242
+ * `V`.
243
+ * @returns the degree of the vertex.
216
244
  */
217
245
  UndirectedGraph.prototype.degreeOf = function (vertexOrId) {
218
246
  var _a;
219
- var vertex = this.getVertex(vertexOrId);
247
+ var vertex = this._getVertex(vertexOrId);
220
248
  if (vertex) {
221
249
  return ((_a = this._edges.get(vertex)) === null || _a === void 0 ? void 0 : _a.length) || 0;
222
250
  }
@@ -225,14 +253,13 @@ var UndirectedGraph = /** @class */ (function (_super) {
225
253
  }
226
254
  };
227
255
  /**
228
- * The function "edgesOf" returns an array of edges connected to a given vertex.
229
- * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
230
- * @returns an array of edges connected to the specified vertex. If the vertex exists in the graph, the function
231
- * returns the array of edges connected to that vertex. If the vertex does not exist in the graph, the function returns
232
- * an empty array.
256
+ * The function "edgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
257
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or an
258
+ * `V`.
259
+ * @returns an array of UndirectedEdge objects.
233
260
  */
234
261
  UndirectedGraph.prototype.edgesOf = function (vertexOrId) {
235
- var vertex = this.getVertex(vertexOrId);
262
+ var vertex = this._getVertex(vertexOrId);
236
263
  if (vertex) {
237
264
  return this._edges.get(vertex) || [];
238
265
  }
@@ -241,8 +268,8 @@ var UndirectedGraph = /** @class */ (function (_super) {
241
268
  }
242
269
  };
243
270
  /**
244
- * The function "edgeSet" returns an array of unique edges from a set of edges.
245
- * @returns The method `edgeSet()` returns an array of type `E[]`.
271
+ * The function "edgeSet" returns an array of unique undirected edges from a set of edges.
272
+ * @returns The method `edgeSet()` returns an array of `E` objects.
246
273
  */
247
274
  UndirectedGraph.prototype.edgeSet = function () {
248
275
  var edgeSet = new Set();
@@ -254,34 +281,34 @@ var UndirectedGraph = /** @class */ (function (_super) {
254
281
  return __spreadArray([], __read(edgeSet), false);
255
282
  };
256
283
  /**
257
- * The function "getEdgesOf" returns an array of edges connected to a given vertex or vertex ID.
258
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
259
- * (`VertexId`).
260
- * @returns an array of edges (E[]) that are connected to the specified vertex or vertex ID.
284
+ * The function "getEdgesOf" returns an array of undirected edges connected to a given vertex or vertex ID.
285
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either an
286
+ * `V` object or a `VertexId`.
287
+ * @returns The function `getEdgesOf` returns an array of `E` objects.
261
288
  */
262
289
  UndirectedGraph.prototype.getEdgesOf = function (vertexOrId) {
263
- var vertex = this.getVertex(vertexOrId);
290
+ var vertex = this._getVertex(vertexOrId);
264
291
  if (!vertex) {
265
292
  return [];
266
293
  }
267
294
  return this._edges.get(vertex) || [];
268
295
  };
269
296
  /**
270
- * The function "getNeighbors" returns an array of neighboring vertices of a given vertex.
271
- * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
272
- * (`VertexId`).
273
- * @returns an array of vertices (V[]).
297
+ * The function `getNeighbors` returns an array of neighboring vertices of a given vertex in an undirected graph.
298
+ * @param {V | VertexId} vertexOrId - The `vertexOrId` parameter can be either an
299
+ * `V` object or a `VertexId`. It represents the vertex for which we want to find the neighbors.
300
+ * @returns an array of UndirectedVertex objects.
274
301
  */
275
302
  UndirectedGraph.prototype.getNeighbors = function (vertexOrId) {
276
303
  var e_2, _a;
277
304
  var neighbors = [];
278
- var vertex = this.getVertex(vertexOrId);
305
+ var vertex = this._getVertex(vertexOrId);
279
306
  if (vertex) {
280
307
  var neighborEdges = this.getEdgesOf(vertex);
281
308
  try {
282
309
  for (var neighborEdges_1 = __values(neighborEdges), neighborEdges_1_1 = neighborEdges_1.next(); !neighborEdges_1_1.done; neighborEdges_1_1 = neighborEdges_1.next()) {
283
310
  var edge = neighborEdges_1_1.value;
284
- var neighbor = this.getVertex(edge.vertices.filter(function (e) { return e !== vertex.id; })[0]);
311
+ var neighbor = this._getVertex(edge.vertices.filter(function (e) { return e !== vertex.id; })[0]);
285
312
  if (neighbor) {
286
313
  neighbors.push(neighbor);
287
314
  }
@@ -298,19 +325,19 @@ var UndirectedGraph = /** @class */ (function (_super) {
298
325
  return neighbors;
299
326
  };
300
327
  /**
301
- * The function "getEndsOfEdge" returns the vertices at the ends of a given edge, or null if the edge does not exist in
302
- * the graph.
303
- * @param {E} edge - The parameter "edge" is of type E, which represents an edge in a graph.
304
- * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
305
- * graph and both vertices are found. If the edge does not exist or one or both vertices are not found, it returns
306
- * `null`.
328
+ * The function "getEndsOfEdge" returns the two vertices that form the ends of a given undirected edge, or null if the
329
+ * edge does not exist in the graph.
330
+ * @param edge - An object representing an undirected edge in a graph. It has a property called "vertices" which is an
331
+ * array containing two vertices that the edge connects.
332
+ * @returns The function `getEndsOfEdge` returns an array containing the two ends of the given `edge` if the edge
333
+ * exists in the graph. If the edge does not exist, it returns `null`.
307
334
  */
308
335
  UndirectedGraph.prototype.getEndsOfEdge = function (edge) {
309
336
  if (!this.hasEdge(edge.vertices[0], edge.vertices[1])) {
310
337
  return null;
311
338
  }
312
- var v1 = this.getVertex(edge.vertices[0]);
313
- var v2 = this.getVertex(edge.vertices[1]);
339
+ var v1 = this._getVertex(edge.vertices[0]);
340
+ var v2 = this._getVertex(edge.vertices[1]);
314
341
  if (v1 && v2) {
315
342
  return [v1, v2];
316
343
  }
@@ -5,7 +5,7 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- export declare class CoordinateSet extends Set {
8
+ export declare class CoordinateSet extends Set<any> {
9
9
  constructor(joint?: string);
10
10
  protected _joint: string;
11
11
  get joint(): string;
@@ -9,4 +9,5 @@ export * from './heap';
9
9
  export * from './priority-queue';
10
10
  export * from './matrix';
11
11
  export * from './trie';
12
+ export * from './interfaces';
12
13
  export * from './types';
@@ -25,4 +25,5 @@ __exportStar(require("./heap"), exports);
25
25
  __exportStar(require("./priority-queue"), exports);
26
26
  __exportStar(require("./matrix"), exports);
27
27
  __exportStar(require("./trie"), exports);
28
+ __exportStar(require("./interfaces"), exports);
28
29
  __exportStar(require("./types"), exports);
@@ -0,0 +1,22 @@
1
+ import { VertexId } from '../types';
2
+ export interface IGraph<V, E> {
3
+ hasVertex(vertexOrId: V | VertexId): boolean;
4
+ _getVertex(vertexOrId: VertexId | V): V | null;
5
+ _getVertexId(vertexOrId: V | VertexId): VertexId;
6
+ createAddVertex(id: VertexId, val?: V): boolean;
7
+ addVertex(newVertex: V): boolean;
8
+ removeVertex(vertexOrId: V | VertexId): boolean;
9
+ removeAllVertices(vertices: V[] | VertexId[]): boolean;
10
+ degreeOf(vertexOrId: V | VertexId): number;
11
+ edgesOf(vertexOrId: V | VertexId): E[];
12
+ hasEdge(src: V | VertexId, dest: V | VertexId): boolean;
13
+ getEdge(srcOrId: V | VertexId, destOrId: V | VertexId): E | null;
14
+ edgeSet(): E[];
15
+ createAddEdge(src: V | VertexId, dest: V | VertexId, weight: number, val: E): boolean;
16
+ addEdge(edge: E): boolean;
17
+ removeEdgeBetween(src: V | VertexId, dest: V | VertexId): E | null;
18
+ removeEdge(edge: E): E | null;
19
+ setEdgeWeight(srcOrId: V | VertexId, destOrId: V | VertexId, weight: number): boolean;
20
+ getMinPathBetween(v1: V | VertexId, v2: V | VertexId, isWeight?: boolean): V[] | null;
21
+ getNeighbors(vertexOrId: V | VertexId): V[];
22
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,27 @@
1
+ import { BinaryTreeNodeId } from '../types';
2
+ import { FamilyPosition } from '../binary-tree';
3
+ export interface IBinaryTreeNode<T, FAMILY extends IBinaryTreeNode<T, FAMILY>> {
4
+ _createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
5
+ get id(): BinaryTreeNodeId;
6
+ set id(v: BinaryTreeNodeId);
7
+ get val(): T;
8
+ set val(v: T);
9
+ get left(): FAMILY | null | undefined;
10
+ set left(v: FAMILY | null | undefined);
11
+ get right(): FAMILY | null | undefined;
12
+ set right(v: FAMILY | null | undefined);
13
+ get parent(): FAMILY | null | undefined;
14
+ set parent(v: FAMILY | null | undefined);
15
+ get familyPosition(): FamilyPosition;
16
+ set familyPosition(v: FamilyPosition);
17
+ get count(): number;
18
+ set count(v: number);
19
+ get height(): number;
20
+ set height(v: number);
21
+ _createNode(id: BinaryTreeNodeId, val: T | null, count?: number): FAMILY | null;
22
+ swapLocation(swapNode: FAMILY): FAMILY;
23
+ clone(): FAMILY | null;
24
+ }
25
+ export interface IBinaryTree<N extends IBinaryTreeNode<N['val'], N>> {
26
+ _createNode(id: BinaryTreeNodeId, val: N['val'] | null, count?: number): N | null;
27
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { VertexId } from '../types';
2
+ export interface IDirectedGraph<V, E> {
3
+ incomingEdgesOf(vertex: V): E[];
4
+ outgoingEdgesOf(vertex: V): E[];
5
+ inDegreeOf(vertexOrId: V | VertexId): number;
6
+ outDegreeOf(vertexOrId: V | VertexId): number;
7
+ getEdgeSrc(e: E): V | null;
8
+ getEdgeDest(e: E): V | null;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });