data-structure-typed 0.8.18 → 1.3.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 (272) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +690 -2
  3. package/dist/bundle.js +2 -0
  4. package/dist/bundle.js.LICENSE.txt +13 -0
  5. package/dist/data-structures/binary-tree/abstract-binary-tree.d.ts +364 -0
  6. package/dist/data-structures/binary-tree/abstract-binary-tree.js +1308 -0
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +85 -18
  8. package/dist/data-structures/binary-tree/avl-tree.js +110 -37
  9. package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +40 -2
  10. package/dist/data-structures/binary-tree/binary-indexed-tree.js +44 -2
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +29 -138
  12. package/dist/data-structures/binary-tree/binary-tree.js +27 -979
  13. package/dist/data-structures/binary-tree/bst.d.ts +118 -28
  14. package/dist/data-structures/binary-tree/bst.js +162 -124
  15. package/dist/data-structures/binary-tree/index.d.ts +1 -0
  16. package/dist/data-structures/binary-tree/index.js +1 -0
  17. package/dist/data-structures/binary-tree/rb-tree.d.ts +18 -1
  18. package/dist/data-structures/binary-tree/rb-tree.js +40 -2
  19. package/dist/data-structures/binary-tree/segment-tree.d.ts +63 -13
  20. package/dist/data-structures/binary-tree/segment-tree.js +80 -17
  21. package/dist/data-structures/binary-tree/tree-multiset.d.ts +213 -10
  22. package/dist/data-structures/binary-tree/tree-multiset.js +682 -9
  23. package/dist/data-structures/graph/abstract-graph.d.ts +270 -64
  24. package/dist/data-structures/graph/abstract-graph.js +365 -92
  25. package/dist/data-structures/graph/directed-graph.d.ts +175 -26
  26. package/dist/data-structures/graph/directed-graph.js +249 -95
  27. package/dist/data-structures/graph/index.d.ts +1 -0
  28. package/dist/data-structures/graph/index.js +1 -0
  29. package/dist/data-structures/graph/map-graph.d.ts +79 -0
  30. package/dist/data-structures/graph/map-graph.js +111 -0
  31. package/dist/data-structures/graph/undirected-graph.d.ts +111 -8
  32. package/dist/data-structures/graph/undirected-graph.js +154 -44
  33. package/dist/data-structures/hash/coordinate-map.d.ts +39 -2
  34. package/dist/data-structures/hash/coordinate-map.js +44 -3
  35. package/dist/data-structures/hash/coordinate-set.d.ts +32 -2
  36. package/dist/data-structures/hash/coordinate-set.js +34 -0
  37. package/dist/data-structures/hash/hash-table.d.ts +2 -1
  38. package/dist/data-structures/hash/hash-table.js +4 -0
  39. package/dist/data-structures/hash/index.d.ts +5 -0
  40. package/dist/data-structures/hash/index.js +5 -0
  41. package/dist/data-structures/hash/pair.d.ts +2 -1
  42. package/dist/data-structures/hash/pair.js +4 -0
  43. package/dist/data-structures/hash/tree-map.d.ts +2 -1
  44. package/dist/data-structures/hash/tree-map.js +4 -0
  45. package/dist/data-structures/hash/tree-set.d.ts +2 -1
  46. package/dist/data-structures/hash/tree-set.js +4 -0
  47. package/dist/data-structures/heap/heap.d.ts +62 -51
  48. package/dist/data-structures/heap/heap.js +106 -63
  49. package/dist/data-structures/heap/max-heap.d.ts +13 -4
  50. package/dist/data-structures/heap/max-heap.js +10 -2
  51. package/dist/data-structures/heap/min-heap.d.ts +14 -4
  52. package/dist/data-structures/heap/min-heap.js +11 -2
  53. package/dist/data-structures/index.d.ts +1 -0
  54. package/dist/data-structures/index.js +1 -0
  55. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +193 -57
  56. package/dist/data-structures/linked-list/doubly-linked-list.js +461 -194
  57. package/dist/data-structures/linked-list/index.d.ts +1 -0
  58. package/dist/data-structures/linked-list/index.js +1 -0
  59. package/dist/data-structures/linked-list/singly-linked-list.d.ts +117 -319
  60. package/dist/data-structures/linked-list/singly-linked-list.js +338 -557
  61. package/dist/data-structures/linked-list/skip-linked-list.d.ts +2 -1
  62. package/dist/data-structures/linked-list/skip-linked-list.js +4 -0
  63. package/dist/data-structures/matrix/matrix.d.ts +12 -0
  64. package/dist/data-structures/matrix/matrix.js +14 -0
  65. package/dist/data-structures/matrix/matrix2d.d.ts +87 -4
  66. package/dist/data-structures/matrix/matrix2d.js +91 -8
  67. package/dist/data-structures/matrix/navigator.d.ts +37 -16
  68. package/dist/data-structures/matrix/navigator.js +28 -0
  69. package/dist/data-structures/matrix/vector2d.d.ts +156 -29
  70. package/dist/data-structures/matrix/vector2d.js +184 -55
  71. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +12 -1
  72. package/dist/data-structures/priority-queue/max-priority-queue.js +28 -4
  73. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +12 -1
  74. package/dist/data-structures/priority-queue/min-priority-queue.js +29 -4
  75. package/dist/data-structures/priority-queue/priority-queue.d.ts +166 -22
  76. package/dist/data-structures/priority-queue/priority-queue.js +219 -75
  77. package/dist/data-structures/queue/deque.d.ts +141 -13
  78. package/dist/data-structures/queue/deque.js +151 -7
  79. package/dist/data-structures/queue/queue.d.ts +68 -42
  80. package/dist/data-structures/queue/queue.js +95 -51
  81. package/dist/data-structures/stack/stack.d.ts +30 -36
  82. package/dist/data-structures/stack/stack.js +31 -37
  83. package/dist/data-structures/tree/index.d.ts +1 -0
  84. package/dist/data-structures/tree/index.js +17 -0
  85. package/dist/data-structures/tree/tree.d.ts +14 -0
  86. package/dist/{types/utils.js → data-structures/tree/tree.js} +26 -19
  87. package/dist/data-structures/trie/trie.d.ts +39 -6
  88. package/dist/data-structures/trie/trie.js +81 -12
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.js +3 -0
  91. package/dist/interfaces/abstract-binary-tree.d.ts +90 -0
  92. package/dist/interfaces/abstract-binary-tree.js +2 -0
  93. package/dist/interfaces/abstract-graph.d.ts +17 -0
  94. package/dist/interfaces/abstract-graph.js +2 -0
  95. package/dist/interfaces/avl-tree.d.ts +9 -0
  96. package/dist/interfaces/avl-tree.js +2 -0
  97. package/dist/interfaces/binary-tree.d.ts +6 -0
  98. package/dist/interfaces/binary-tree.js +2 -0
  99. package/dist/interfaces/bst.d.ts +17 -0
  100. package/dist/interfaces/bst.js +2 -0
  101. package/dist/interfaces/directed-graph.d.ts +12 -0
  102. package/dist/interfaces/directed-graph.js +2 -0
  103. package/dist/interfaces/doubly-linked-list.js +2 -0
  104. package/dist/interfaces/heap.js +2 -0
  105. package/dist/interfaces/index.d.ts +15 -0
  106. package/dist/interfaces/index.js +31 -0
  107. package/dist/interfaces/navigator.js +2 -0
  108. package/dist/interfaces/priority-queue.js +2 -0
  109. package/dist/interfaces/rb-tree.d.ts +8 -0
  110. package/dist/interfaces/rb-tree.js +2 -0
  111. package/dist/interfaces/segment-tree.js +2 -0
  112. package/dist/interfaces/singly-linked-list.js +2 -0
  113. package/dist/interfaces/tree-multiset.d.ts +7 -0
  114. package/dist/interfaces/tree-multiset.js +2 -0
  115. package/dist/interfaces/undirected-graph.d.ts +5 -0
  116. package/dist/interfaces/undirected-graph.js +2 -0
  117. package/dist/types/data-structures/abstract-binary-tree.d.ts +34 -0
  118. package/dist/types/data-structures/abstract-binary-tree.js +25 -0
  119. package/dist/types/data-structures/abstract-graph.d.ts +11 -0
  120. package/dist/types/data-structures/abstract-graph.js +2 -0
  121. package/dist/types/data-structures/avl-tree.d.ts +4 -0
  122. package/dist/types/data-structures/avl-tree.js +2 -0
  123. package/dist/types/data-structures/binary-tree.d.ts +4 -0
  124. package/dist/types/data-structures/binary-tree.js +2 -0
  125. package/dist/types/data-structures/bst.d.ts +13 -0
  126. package/dist/types/data-structures/bst.js +9 -0
  127. package/dist/types/data-structures/directed-graph.d.ts +6 -0
  128. package/dist/types/data-structures/directed-graph.js +9 -0
  129. package/dist/types/data-structures/doubly-linked-list.js +2 -0
  130. package/dist/types/data-structures/heap.d.ts +3 -0
  131. package/dist/types/data-structures/heap.js +2 -0
  132. package/dist/types/data-structures/index.d.ts +13 -7
  133. package/dist/types/data-structures/index.js +31 -0
  134. package/dist/types/data-structures/map-graph.d.ts +1 -0
  135. package/dist/types/data-structures/map-graph.js +2 -0
  136. package/dist/types/data-structures/navigator.d.ts +14 -0
  137. package/dist/types/data-structures/navigator.js +2 -0
  138. package/dist/types/data-structures/priority-queue.d.ts +7 -0
  139. package/dist/types/data-structures/priority-queue.js +2 -0
  140. package/dist/types/data-structures/rb-tree.d.ts +8 -0
  141. package/dist/types/data-structures/rb-tree.js +8 -0
  142. package/dist/types/data-structures/segment-tree.d.ts +1 -0
  143. package/dist/types/data-structures/segment-tree.js +2 -0
  144. package/dist/types/data-structures/singly-linked-list.js +2 -0
  145. package/dist/types/data-structures/tree-multiset.d.ts +4 -0
  146. package/dist/types/data-structures/tree-multiset.js +2 -0
  147. package/dist/types/helpers.d.ts +1 -0
  148. package/dist/types/helpers.js +2 -0
  149. package/dist/types/index.d.ts +2 -0
  150. package/dist/types/index.js +2 -0
  151. package/dist/types/utils/index.d.ts +2 -0
  152. package/dist/types/utils/index.js +18 -0
  153. package/dist/types/utils/utils.d.ts +7 -0
  154. package/dist/types/utils/utils.js +2 -0
  155. package/dist/types/utils/validate-type.d.ts +19 -0
  156. package/dist/types/utils/validate-type.js +2 -0
  157. package/dist/utils/index.js +17 -0
  158. package/dist/utils/utils.d.ts +19 -0
  159. package/dist/{data-structures/trampoline.js → utils/utils.js} +26 -12
  160. package/package.json +106 -55
  161. package/.idea/data-structure-typed.iml +0 -12
  162. package/.idea/modules.xml +0 -8
  163. package/.idea/vcs.xml +0 -6
  164. package/dist/data-structures/trampoline.d.ts +0 -25
  165. package/dist/types/data-structures/binary-tree/aa-tree.d.ts +0 -2
  166. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +0 -21
  167. package/dist/types/data-structures/binary-tree/b-tree.d.ts +0 -2
  168. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -8
  169. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +0 -140
  170. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -32
  171. package/dist/types/data-structures/binary-tree/index.d.ts +0 -4
  172. package/dist/types/data-structures/binary-tree/rb-tree.d.ts +0 -2
  173. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +0 -33
  174. package/dist/types/data-structures/binary-tree/splay-tree.d.ts +0 -2
  175. package/dist/types/data-structures/binary-tree/tree-multiset.d.ts +0 -11
  176. package/dist/types/data-structures/binary-tree/two-three-tree.d.ts +0 -2
  177. package/dist/types/data-structures/graph/abstract-graph.d.ts +0 -126
  178. package/dist/types/data-structures/graph/directed-graph.d.ts +0 -51
  179. package/dist/types/data-structures/graph/index.d.ts +0 -3
  180. package/dist/types/data-structures/graph/undirected-graph.d.ts +0 -24
  181. package/dist/types/data-structures/hash/coordinate-map.d.ts +0 -8
  182. package/dist/types/data-structures/hash/coordinate-set.d.ts +0 -7
  183. package/dist/types/data-structures/hash/index.d.ts +0 -1
  184. package/dist/types/data-structures/heap/heap.d.ts +0 -72
  185. package/dist/types/data-structures/heap/index.d.ts +0 -3
  186. package/dist/types/data-structures/heap/max-heap.d.ts +0 -14
  187. package/dist/types/data-structures/heap/min-heap.d.ts +0 -14
  188. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +0 -59
  189. package/dist/types/data-structures/linked-list/index.d.ts +0 -2
  190. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +0 -358
  191. package/dist/types/data-structures/matrix/index.d.ts +0 -3
  192. package/dist/types/data-structures/matrix/matrix.d.ts +0 -9
  193. package/dist/types/data-structures/matrix/matrix2d.d.ts +0 -25
  194. package/dist/types/data-structures/matrix/navigator.d.ts +0 -31
  195. package/dist/types/data-structures/matrix/vector2d.d.ts +0 -74
  196. package/dist/types/data-structures/priority-queue/index.d.ts +0 -3
  197. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +0 -4
  198. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +0 -4
  199. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +0 -36
  200. package/dist/types/data-structures/queue/deque.d.ts +0 -37
  201. package/dist/types/data-structures/queue/index.d.ts +0 -1
  202. package/dist/types/data-structures/queue/queue.d.ts +0 -76
  203. package/dist/types/data-structures/stack/index.d.ts +0 -1
  204. package/dist/types/data-structures/stack/stack.d.ts +0 -69
  205. package/dist/types/data-structures/trampoline.d.ts +0 -25
  206. package/dist/types/data-structures/trie/index.d.ts +0 -1
  207. package/dist/types/data-structures/trie/trie.d.ts +0 -28
  208. package/dist/types/types/utils.d.ts +0 -46
  209. package/dist/types/utils.d.ts +0 -46
  210. package/dist/utils.d.ts +0 -122
  211. package/dist/utils.js +0 -569
  212. package/src/data-structures/binary-tree/aa-tree.ts +0 -3
  213. package/src/data-structures/binary-tree/avl-tree.ts +0 -232
  214. package/src/data-structures/binary-tree/b-tree.ts +0 -3
  215. package/src/data-structures/binary-tree/binary-indexed-tree.ts +0 -33
  216. package/src/data-structures/binary-tree/binary-tree.ts +0 -1088
  217. package/src/data-structures/binary-tree/bst.ts +0 -404
  218. package/src/data-structures/binary-tree/index.ts +0 -11
  219. package/src/data-structures/binary-tree/rb-tree.ts +0 -3
  220. package/src/data-structures/binary-tree/segment-tree.ts +0 -164
  221. package/src/data-structures/binary-tree/splay-tree.ts +0 -3
  222. package/src/data-structures/binary-tree/tree-multiset.ts +0 -21
  223. package/src/data-structures/binary-tree/two-three-tree.ts +0 -3
  224. package/src/data-structures/graph/abstract-graph.ts +0 -789
  225. package/src/data-structures/graph/directed-graph.ts +0 -322
  226. package/src/data-structures/graph/index.ts +0 -3
  227. package/src/data-structures/graph/undirected-graph.ts +0 -154
  228. package/src/data-structures/hash/coordinate-map.ts +0 -24
  229. package/src/data-structures/hash/coordinate-set.ts +0 -20
  230. package/src/data-structures/hash/hash-table.ts +0 -1
  231. package/src/data-structures/hash/index.ts +0 -1
  232. package/src/data-structures/heap/heap.ts +0 -136
  233. package/src/data-structures/heap/index.ts +0 -3
  234. package/src/data-structures/heap/max-heap.ts +0 -22
  235. package/src/data-structures/heap/min-heap.ts +0 -24
  236. package/src/data-structures/index.ts +0 -11
  237. package/src/data-structures/linked-list/doubly-linked-list.ts +0 -258
  238. package/src/data-structures/linked-list/index.ts +0 -2
  239. package/src/data-structures/linked-list/singly-linked-list.ts +0 -750
  240. package/src/data-structures/linked-list/skip-linked-list.ts +0 -1
  241. package/src/data-structures/matrix/index.ts +0 -4
  242. package/src/data-structures/matrix/matrix.ts +0 -13
  243. package/src/data-structures/matrix/matrix2d.ts +0 -125
  244. package/src/data-structures/matrix/navigator.ts +0 -99
  245. package/src/data-structures/matrix/vector2d.ts +0 -189
  246. package/src/data-structures/priority-queue/index.ts +0 -3
  247. package/src/data-structures/priority-queue/max-priority-queue.ts +0 -12
  248. package/src/data-structures/priority-queue/min-priority-queue.ts +0 -12
  249. package/src/data-structures/priority-queue/priority-queue.ts +0 -208
  250. package/src/data-structures/queue/deque.ts +0 -139
  251. package/src/data-structures/queue/index.ts +0 -2
  252. package/src/data-structures/queue/queue.ts +0 -123
  253. package/src/data-structures/stack/index.ts +0 -1
  254. package/src/data-structures/stack/stack.ts +0 -104
  255. package/src/data-structures/trampoline.ts +0 -91
  256. package/src/data-structures/trie/index.ts +0 -1
  257. package/src/data-structures/trie/trie.ts +0 -153
  258. package/src/index.ts +0 -1
  259. package/src/types/index.ts +0 -1
  260. package/src/types/patches/index.d.ts +0 -0
  261. package/src/types/utils.ts +0 -158
  262. package/src/utils.ts +0 -605
  263. package/tsconfig.json +0 -53
  264. /package/dist/{types/data-structures/hash/hash-table.d.ts → interfaces/doubly-linked-list.d.ts} +0 -0
  265. /package/dist/{types/data-structures/hash/pair.d.ts → interfaces/heap.d.ts} +0 -0
  266. /package/dist/{types/data-structures/hash/tree-map.d.ts → interfaces/navigator.d.ts} +0 -0
  267. /package/dist/{types/data-structures/hash/tree-set.d.ts → interfaces/priority-queue.d.ts} +0 -0
  268. /package/dist/{types/data-structures/linked-list/skip-linked-list.d.ts → interfaces/segment-tree.d.ts} +0 -0
  269. /package/{src/data-structures/hash/pair.ts → dist/interfaces/singly-linked-list.d.ts} +0 -0
  270. /package/{src/data-structures/hash/tree-map.ts → dist/types/data-structures/doubly-linked-list.d.ts} +0 -0
  271. /package/{src/data-structures/hash/tree-set.ts → dist/types/data-structures/singly-linked-list.d.ts} +0 -0
  272. /package/dist/{types/types → utils}/index.d.ts +0 -0
@@ -1,17 +1,42 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DirectedGraph = exports.DirectedEdge = exports.DirectedVertex = void 0;
4
+ /**
5
+ * data-structure-typed
6
+ *
7
+ * @author Tyler Zeng
8
+ * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
+ * @license MIT License
10
+ */
4
11
  const utils_1 = require("../../utils");
5
12
  const abstract_graph_1 = require("./abstract-graph");
6
13
  class DirectedVertex extends abstract_graph_1.AbstractVertex {
7
- constructor(id) {
8
- super(id);
14
+ /**
15
+ * The constructor function initializes a vertex with an optional value.
16
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex. It is
17
+ * used to uniquely identify the vertex within a graph or data structure.
18
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to initialize the value of the
19
+ * vertex. If no value is provided, the vertex will be initialized with a default value.
20
+ */
21
+ constructor(id, val) {
22
+ super(id, val);
9
23
  }
10
24
  }
11
25
  exports.DirectedVertex = DirectedVertex;
12
26
  class DirectedEdge extends abstract_graph_1.AbstractEdge {
13
- constructor(src, dest, weight) {
14
- super(weight);
27
+ /**
28
+ * The constructor function initializes the source and destination vertices of an edge, along with an optional weight
29
+ * and value.
30
+ * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
31
+ * a graph.
32
+ * @param {VertexId} dest - The `dest` parameter represents the destination vertex of an edge. It is of type
33
+ * `VertexId`, which is likely a unique identifier for a vertex in a graph.
34
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
35
+ * @param {T} [val] - The `val` parameter is an optional parameter of type `T`. It represents the value associated with
36
+ * the edge.
37
+ */
38
+ constructor(src, dest, weight, val) {
39
+ super(weight, val);
15
40
  this._src = src;
16
41
  this._dest = dest;
17
42
  }
@@ -29,18 +54,67 @@ class DirectedEdge extends abstract_graph_1.AbstractEdge {
29
54
  }
30
55
  }
31
56
  exports.DirectedEdge = DirectedEdge;
32
- // Strongly connected, One direction connected, Weakly connected
33
57
  class DirectedGraph extends abstract_graph_1.AbstractGraph {
58
+ /**
59
+ * The constructor function initializes an instance of a class.
60
+ */
34
61
  constructor() {
35
62
  super();
36
63
  this._outEdgeMap = new Map();
37
64
  this._inEdgeMap = new Map();
38
65
  }
66
+ get outEdgeMap() {
67
+ return this._outEdgeMap;
68
+ }
69
+ get inEdgeMap() {
70
+ return this._inEdgeMap;
71
+ }
72
+ /**
73
+ * 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.
74
+ * 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.
75
+ */
76
+ /**
77
+ * The function creates a new vertex with an optional value and returns it.
78
+ * @param {VertexId} id - The `id` parameter is the unique identifier for the vertex. It is of type `VertexId`, which
79
+ * could be a number or a string depending on how you want to identify your vertices.
80
+ * @param [val] - The 'val' parameter is an optional value that can be assigned to the vertex. If a value is provided,
81
+ * it will be assigned to the 'val' property of the vertex. If no value is provided, the 'val' property will be
82
+ * assigned the same value as the 'id' parameter
83
+ * @returns a new instance of a DirectedVertex object, casted as type V.
84
+ */
85
+ createVertex(id, val) {
86
+ return new DirectedVertex(id, val !== null && val !== void 0 ? val : id);
87
+ }
88
+ /**
89
+ * 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.
90
+ * 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.
91
+ */
92
+ /**
93
+ * The function creates a directed edge between two vertices with an optional weight and value.
94
+ * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
95
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge.
96
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge. If no
97
+ * weight is provided, it defaults to 1.
98
+ * @param [val] - The 'val' parameter is an optional value that can be assigned to the edge. It can be of any type and
99
+ * is used to store additional information or data associated with the edge.
100
+ * @returns a new instance of a DirectedEdge object, casted as type E.
101
+ */
102
+ createEdge(src, dest, weight, val) {
103
+ return new DirectedEdge(src, dest, weight !== null && weight !== void 0 ? weight : 1, val);
104
+ }
105
+ /**
106
+ * The `getEdge` function retrieves an edge between two vertices based on their source and destination IDs.
107
+ * @param {V | null | VertexId} srcOrId - The source vertex or its ID. It can be either a vertex object or a vertex ID.
108
+ * @param {V | null | VertexId} destOrId - The `destOrId` parameter in the `getEdge` function represents the
109
+ * destination vertex of the edge. It can be either a vertex object (`V`), a vertex ID (`VertexId`), or `null` if the
110
+ * destination is not specified.
111
+ * @returns the first edge found between the source and destination vertices, or null if no such edge is found.
112
+ */
39
113
  getEdge(srcOrId, destOrId) {
40
114
  let edges = [];
41
115
  if (srcOrId !== null && destOrId !== null) {
42
- const src = this.getVertex(srcOrId);
43
- const dest = this.getVertex(destOrId);
116
+ const src = this._getVertex(srcOrId);
117
+ const dest = this._getVertex(destOrId);
44
118
  if (src && dest) {
45
119
  const srcOutEdges = this._outEdgeMap.get(src);
46
120
  if (srcOutEdges) {
@@ -50,102 +124,149 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
50
124
  }
51
125
  return edges[0] || null;
52
126
  }
53
- addEdge(edge) {
54
- if (!(this.containsVertex(edge.src) && this.containsVertex(edge.dest))) {
55
- return false;
56
- }
57
- const srcVertex = this.getVertex(edge.src);
58
- const destVertex = this.getVertex(edge.dest);
59
- // TODO after no-non-null-assertion not ensure the logic
60
- if (srcVertex && destVertex) {
61
- const srcOutEdges = this._outEdgeMap.get(srcVertex);
62
- if (srcOutEdges) {
63
- srcOutEdges.push(edge);
64
- }
65
- else {
66
- this._outEdgeMap.set(srcVertex, [edge]);
67
- }
68
- const destInEdges = this._inEdgeMap.get(destVertex);
69
- if (destInEdges) {
70
- destInEdges.push(edge);
71
- }
72
- else {
73
- this._inEdgeMap.set(destVertex, [edge]);
74
- }
75
- return true;
76
- }
77
- else {
78
- return false;
79
- }
80
- }
81
- removeEdgeBetween(srcOrId, destOrId) {
82
- const src = this.getVertex(srcOrId);
83
- const dest = this.getVertex(destOrId);
127
+ /**
128
+ * The function removes an edge between two vertices in a graph and returns the removed edge.
129
+ * @param {V | VertexId} srcOrId - The source vertex or its ID.
130
+ * @param {V | VertexId} destOrId - The `destOrId` parameter represents the destination vertex or its ID.
131
+ * @returns the removed edge (E) if it exists, or null if either the source or destination vertex does not exist.
132
+ */
133
+ removeEdgeSrcToDest(srcOrId, destOrId) {
134
+ const src = this._getVertex(srcOrId);
135
+ const dest = this._getVertex(destOrId);
84
136
  let removed = null;
85
137
  if (!src || !dest) {
86
138
  return null;
87
139
  }
88
140
  const srcOutEdges = this._outEdgeMap.get(src);
89
141
  if (srcOutEdges) {
90
- (0, utils_1.arrayRemove)(srcOutEdges, edge => edge.dest === dest.id);
142
+ (0, utils_1.arrayRemove)(srcOutEdges, (edge) => edge.dest === dest.id);
91
143
  }
92
144
  const destInEdges = this._inEdgeMap.get(dest);
93
145
  if (destInEdges) {
94
- removed = (0, utils_1.arrayRemove)(destInEdges, edge => edge.src === src.id)[0] || null;
146
+ removed = (0, utils_1.arrayRemove)(destInEdges, (edge) => edge.src === src.id)[0] || null;
95
147
  }
96
148
  return removed;
97
149
  }
150
+ /**
151
+ * The function removes an edge from a graph and returns the removed edge, or null if the edge was not found.
152
+ * @param {E} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
153
+ * and `dest`, which represent the source and destination vertices of the edge, respectively.
154
+ * @returns The method `removeEdge` returns the removed edge (`E`) if it exists, or `null` if the edge does not exist.
155
+ */
98
156
  removeEdge(edge) {
99
157
  let removed = null;
100
- const src = this.getVertex(edge.src);
101
- const dest = this.getVertex(edge.dest);
158
+ const src = this._getVertex(edge.src);
159
+ const dest = this._getVertex(edge.dest);
102
160
  if (src && dest) {
103
161
  const srcOutEdges = this._outEdgeMap.get(src);
104
162
  if (srcOutEdges && srcOutEdges.length > 0) {
105
- (0, utils_1.arrayRemove)(srcOutEdges, edge => edge.src === src.id);
163
+ (0, utils_1.arrayRemove)(srcOutEdges, (edge) => edge.src === src.id);
106
164
  }
107
165
  const destInEdges = this._inEdgeMap.get(dest);
108
166
  if (destInEdges && destInEdges.length > 0) {
109
- removed = (0, utils_1.arrayRemove)(destInEdges, edge => edge.dest === dest.id)[0];
167
+ removed = (0, utils_1.arrayRemove)(destInEdges, (edge) => edge.dest === dest.id)[0];
110
168
  }
111
169
  }
112
170
  return removed;
113
171
  }
114
- removeAllEdges(src, dest) {
115
- return [];
172
+ /**
173
+ * The function removes edges between two vertices and returns the removed edges.
174
+ * @param {VertexId | V} v1 - The parameter `v1` can be either a `VertexId` or a `V`. A `VertexId` represents the
175
+ * unique identifier of a vertex in a graph, while `V` represents the actual vertex object.
176
+ * @param {VertexId | V} v2 - The parameter `v2` represents either a `VertexId` or a `V` object. It is used to specify
177
+ * the second vertex in the edge that needs to be removed.
178
+ * @returns an array of removed edges (E[]).
179
+ */
180
+ removeEdgesBetween(v1, v2) {
181
+ const removed = [];
182
+ if (v1 && v2) {
183
+ const v1ToV2 = this.removeEdgeSrcToDest(v1, v2);
184
+ const v2ToV1 = this.removeEdgeSrcToDest(v2, v1);
185
+ v1ToV2 && removed.push(v1ToV2);
186
+ v2ToV1 && removed.push(v2ToV1);
187
+ }
188
+ return removed;
116
189
  }
190
+ /**
191
+ * The function `incomingEdgesOf` returns an array of incoming edges for a given vertex or vertex ID.
192
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
193
+ * (`VertexId`).
194
+ * @returns The method `incomingEdgesOf` returns an array of edges (`E[]`).
195
+ */
117
196
  incomingEdgesOf(vertexOrId) {
118
- const target = this.getVertex(vertexOrId);
197
+ const target = this._getVertex(vertexOrId);
119
198
  if (target) {
120
- return this._inEdgeMap.get(target) || [];
199
+ return this.inEdgeMap.get(target) || [];
121
200
  }
122
201
  return [];
123
202
  }
203
+ /**
204
+ * The function `outgoingEdgesOf` returns an array of outgoing edges from a given vertex or vertex ID.
205
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
206
+ * (`VertexId`).
207
+ * @returns The method `outgoingEdgesOf` returns an array of edges (`E[]`).
208
+ */
124
209
  outgoingEdgesOf(vertexOrId) {
125
- const target = this.getVertex(vertexOrId);
210
+ const target = this._getVertex(vertexOrId);
126
211
  if (target) {
127
212
  return this._outEdgeMap.get(target) || [];
128
213
  }
129
214
  return [];
130
215
  }
216
+ /**
217
+ * The function "degreeOf" returns the total degree of a vertex, which is the sum of its out-degree and in-degree.
218
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
219
+ * @returns The sum of the out-degree and in-degree of the specified vertex or vertex ID.
220
+ */
131
221
  degreeOf(vertexOrId) {
132
222
  return this.outDegreeOf(vertexOrId) + this.inDegreeOf(vertexOrId);
133
223
  }
224
+ /**
225
+ * The function "inDegreeOf" returns the number of incoming edges for a given vertex.
226
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
227
+ * @returns The number of incoming edges of the specified vertex or vertex ID.
228
+ */
134
229
  inDegreeOf(vertexOrId) {
135
230
  return this.incomingEdgesOf(vertexOrId).length;
136
231
  }
232
+ /**
233
+ * The function `outDegreeOf` returns the number of outgoing edges from a given vertex.
234
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
235
+ * @returns The number of outgoing edges from the specified vertex or vertex ID.
236
+ */
137
237
  outDegreeOf(vertexOrId) {
138
238
  return this.outgoingEdgesOf(vertexOrId).length;
139
239
  }
240
+ /**
241
+ * The function "edgesOf" returns an array of both outgoing and incoming edges of a given vertex or vertex ID.
242
+ * @param {VertexId | V} vertexOrId - The parameter `vertexOrId` can be either a `VertexId` or a `V`.
243
+ * @returns The function `edgesOf` returns an array of edges.
244
+ */
140
245
  edgesOf(vertexOrId) {
141
246
  return [...this.outgoingEdgesOf(vertexOrId), ...this.incomingEdgesOf(vertexOrId)];
142
247
  }
248
+ /**
249
+ * The function "getEdgeSrc" returns the source vertex of an edge, or null if the edge does not exist.
250
+ * @param {E} e - The parameter "e" is of type E, which represents an edge in a graph.
251
+ * @returns either a vertex object (V) or null.
252
+ */
143
253
  getEdgeSrc(e) {
144
- return this.getVertex(e.src);
254
+ return this._getVertex(e.src);
145
255
  }
256
+ /**
257
+ * The function "getEdgeDest" returns the destination vertex of an edge.
258
+ * @param {E} e - The parameter "e" is of type "E", which represents an edge in a graph.
259
+ * @returns either a vertex object of type V or null.
260
+ */
146
261
  getEdgeDest(e) {
147
- return this.getVertex(e.dest);
262
+ return this._getVertex(e.dest);
148
263
  }
264
+ /**
265
+ * The function `getDestinations` returns an array of destination vertices connected to a given vertex.
266
+ * @param {V | VertexId | null} vertex - The `vertex` parameter represents the starting vertex from which we want to
267
+ * find the destinations. It can be either a `V` object, a `VertexId` value, or `null`.
268
+ * @returns an array of vertices (V[]).
269
+ */
149
270
  getDestinations(vertex) {
150
271
  if (vertex === null) {
151
272
  return [];
@@ -160,48 +281,23 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
160
281
  }
161
282
  return destinations;
162
283
  }
163
- /**--- start find cycles --- */
164
284
  /**
165
- * when stored with adjacency list time: O(V+E)
166
- * when stored with adjacency matrix time: O(V^2)
285
+ * The `topologicalSort` function performs a topological sort on a graph and returns an array of vertices or vertex IDs
286
+ * in the sorted order, or null if the graph contains a cycle.
287
+ * @param {'vertex' | 'id'} [propertyName] - The `propertyName` parameter is an optional parameter that specifies the
288
+ * property to use for sorting the vertices. It can have two possible values: 'vertex' or 'id'. If 'vertex' is
289
+ * specified, the vertices themselves will be used for sorting. If 'id' is specified, the ids of
290
+ * @returns an array of vertices or vertex IDs in topological order. If there is a cycle in the graph, it returns null.
167
291
  */
168
- topologicalSort() {
169
- // vector<vector<int>> g;
170
- // vector<int> color;
171
- // int last;
172
- // bool hasCycle;
173
- //
174
- // bool topo_sort() {
175
- // int n = g.size();
176
- // vector<int> degree(n, 0);
177
- // queue<int> q;
178
- // for (int i = 0; i < n; i++) {
179
- // degree[i] = g[i].size();
180
- // if (degree[i] <= 1) {
181
- // q.push(i);
182
- // }
183
- // }
184
- // int cnt = 0;
185
- // while (!q.empty()) {
186
- // cnt++;
187
- // int root = q.front();
188
- // q.pop();
189
- // for (auto child : g[root]) {
190
- // degree[child]--;
191
- // if (degree[child] == 1) {
192
- // q.push(child);
193
- // }
194
- // }
195
- // }
196
- // return (cnt != n);
197
- // }
292
+ topologicalSort(propertyName) {
293
+ propertyName = propertyName !== null && propertyName !== void 0 ? propertyName : 'id';
198
294
  // When judging whether there is a cycle in the undirected graph, all nodes with degree of **<= 1** are enqueued
199
295
  // When judging whether there is a cycle in the directed graph, all nodes with **in degree = 0** are enqueued
200
296
  const statusMap = new Map();
201
- for (const entry of this._vertices) {
297
+ for (const entry of this.vertices) {
202
298
  statusMap.set(entry[1], 0);
203
299
  }
204
- const sorted = [];
300
+ let sorted = [];
205
301
  let hasCycle = false;
206
302
  const dfs = (cur) => {
207
303
  statusMap.set(cur, 1);
@@ -218,17 +314,21 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
218
314
  statusMap.set(cur, 2);
219
315
  sorted.push(cur);
220
316
  };
221
- for (const entry of this._vertices) {
317
+ for (const entry of this.vertices) {
222
318
  if (statusMap.get(entry[1]) === 0) {
223
319
  dfs(entry[1]);
224
320
  }
225
321
  }
226
- if (hasCycle) {
322
+ if (hasCycle)
227
323
  return null;
228
- }
324
+ if (propertyName === 'id')
325
+ sorted = sorted.map(vertex => vertex instanceof DirectedVertex ? vertex.id : vertex);
229
326
  return sorted.reverse();
230
327
  }
231
- /**--- end find cycles --- */
328
+ /**
329
+ * The `edgeSet` function returns an array of all the edges in the graph.
330
+ * @returns The `edgeSet()` method returns an array of edges (`E[]`).
331
+ */
232
332
  edgeSet() {
233
333
  let edges = [];
234
334
  this._outEdgeMap.forEach(outEdges => {
@@ -236,13 +336,19 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
236
336
  });
237
337
  return edges;
238
338
  }
339
+ /**
340
+ * The function `getNeighbors` returns an array of neighboring vertices of a given vertex or vertex ID in a graph.
341
+ * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can be either a vertex object (`V`) or a vertex ID
342
+ * (`VertexId`).
343
+ * @returns an array of vertices (V[]).
344
+ */
239
345
  getNeighbors(vertexOrId) {
240
346
  const neighbors = [];
241
- const vertex = this.getVertex(vertexOrId);
347
+ const vertex = this._getVertex(vertexOrId);
242
348
  if (vertex) {
243
349
  const outEdges = this.outgoingEdgesOf(vertex);
244
350
  for (const outEdge of outEdges) {
245
- const neighbor = this.getVertex(outEdge.dest);
351
+ const neighbor = this._getVertex(outEdge.dest);
246
352
  // TODO after no-non-null-assertion not ensure the logic
247
353
  if (neighbor) {
248
354
  neighbors.push(neighbor);
@@ -251,12 +357,19 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
251
357
  }
252
358
  return neighbors;
253
359
  }
360
+ /**
361
+ * The function "getEndsOfEdge" returns the source and destination vertices of an edge if it exists in the graph,
362
+ * otherwise it returns null.
363
+ * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph.
364
+ * @returns The function `getEndsOfEdge` returns an array containing two vertices `[V, V]` if the edge exists in the
365
+ * graph. If the edge does not exist, it returns `null`.
366
+ */
254
367
  getEndsOfEdge(edge) {
255
- if (!this.containsEdge(edge.src, edge.dest)) {
368
+ if (!this.hasEdge(edge.src, edge.dest)) {
256
369
  return null;
257
370
  }
258
- const v1 = this.getVertex(edge.src);
259
- const v2 = this.getVertex(edge.dest);
371
+ const v1 = this._getVertex(edge.src);
372
+ const v2 = this._getVertex(edge.dest);
260
373
  if (v1 && v2) {
261
374
  return [v1, v2];
262
375
  }
@@ -264,5 +377,46 @@ class DirectedGraph extends abstract_graph_1.AbstractGraph {
264
377
  return null;
265
378
  }
266
379
  }
380
+ /**
381
+ * The function `_addEdgeOnly` adds an edge to a graph if the source and destination vertices exist.
382
+ * @param {E} edge - The parameter `edge` is of type `E`, which represents an edge in a graph. It is the edge that
383
+ * needs to be added to the graph.
384
+ * @returns a boolean value. It returns true if the edge was successfully added to the graph, and false if either the
385
+ * source or destination vertex does not exist in the graph.
386
+ */
387
+ _addEdgeOnly(edge) {
388
+ if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
389
+ return false;
390
+ }
391
+ const srcVertex = this._getVertex(edge.src);
392
+ const destVertex = this._getVertex(edge.dest);
393
+ // TODO after no-non-null-assertion not ensure the logic
394
+ if (srcVertex && destVertex) {
395
+ const srcOutEdges = this._outEdgeMap.get(srcVertex);
396
+ if (srcOutEdges) {
397
+ srcOutEdges.push(edge);
398
+ }
399
+ else {
400
+ this._outEdgeMap.set(srcVertex, [edge]);
401
+ }
402
+ const destInEdges = this._inEdgeMap.get(destVertex);
403
+ if (destInEdges) {
404
+ destInEdges.push(edge);
405
+ }
406
+ else {
407
+ this._inEdgeMap.set(destVertex, [edge]);
408
+ }
409
+ return true;
410
+ }
411
+ else {
412
+ return false;
413
+ }
414
+ }
415
+ _setOutEdgeMap(value) {
416
+ this._outEdgeMap = value;
417
+ }
418
+ _setInEdgeMap(value) {
419
+ this._inEdgeMap = value;
420
+ }
267
421
  }
268
422
  exports.DirectedGraph = DirectedGraph;
@@ -1,3 +1,4 @@
1
1
  export * from './abstract-graph';
2
2
  export * from './directed-graph';
3
3
  export * from './undirected-graph';
4
+ export * from './map-graph';
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./abstract-graph"), exports);
18
18
  __exportStar(require("./directed-graph"), exports);
19
19
  __exportStar(require("./undirected-graph"), exports);
20
+ __exportStar(require("./map-graph"), exports);
@@ -0,0 +1,79 @@
1
+ import { MapGraphCoordinate, VertexId } from '../../types';
2
+ import { DirectedEdge, DirectedGraph, DirectedVertex } from './directed-graph';
3
+ export declare class MapVertex<T = any> extends DirectedVertex<T> {
4
+ /**
5
+ * The constructor function initializes an object with an id, latitude, longitude, and an optional value.
6
+ * @param {VertexId} id - The `id` parameter is of type `VertexId` and represents the identifier of the vertex.
7
+ * @param {number} lat - The "lat" parameter represents the latitude of a vertex. Latitude is a geographic coordinate
8
+ * that specifies the north-south position of a point on the Earth's surface. It is measured in degrees, with positive
9
+ * values representing points north of the equator and negative values representing points south of the equator.
10
+ * @param {number} long - The "long" parameter represents the longitude of a location. Longitude is a geographic
11
+ * coordinate that specifies the east-west position of a point on the Earth's surface. It is measured in degrees, with
12
+ * values ranging from -180 to 180.
13
+ * @param {T} [val] - The "val" parameter is an optional value of type T. It is not required to be provided when
14
+ * creating an instance of the class.
15
+ */
16
+ constructor(id: VertexId, lat: number, long: number, val?: T);
17
+ private _lat;
18
+ get lat(): number;
19
+ set lat(value: number);
20
+ private _long;
21
+ get long(): number;
22
+ set long(value: number);
23
+ }
24
+ export declare class MapEdge<T = any> extends DirectedEdge<T> {
25
+ /**
26
+ * The constructor function initializes a new instance of a class with the given source, destination, weight, and
27
+ * value.
28
+ * @param {VertexId} src - The `src` parameter is the source vertex ID. It represents the starting point of an edge in
29
+ * a graph.
30
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for an edge.
31
+ * @param {number} [weight] - The weight parameter is an optional number that represents the weight of the edge.
32
+ * @param {T} [val] - The "val" parameter is an optional parameter of type T. It is used to store additional
33
+ * information or data associated with the edge.
34
+ */
35
+ constructor(src: VertexId, dest: VertexId, weight?: number, val?: T);
36
+ }
37
+ export declare class MapGraph<V extends MapVertex<V['val']> = MapVertex, E extends MapEdge = MapEdge> extends DirectedGraph<V, E> {
38
+ /**
39
+ * The constructor function initializes the origin and bottomRight properties of a MapGraphCoordinate object.
40
+ * @param {MapGraphCoordinate} origin - The `origin` parameter is a `MapGraphCoordinate` object that represents the
41
+ * starting point or reference point of the map graph. It defines the coordinates of the top-left corner of the map
42
+ * graph.
43
+ * @param {MapGraphCoordinate} [bottomRight] - The `bottomRight` parameter is an optional parameter of type
44
+ * `MapGraphCoordinate`. It represents the bottom right coordinate of a map graph. If this parameter is not provided,
45
+ * it will default to `undefined`.
46
+ */
47
+ constructor(origin: MapGraphCoordinate, bottomRight?: MapGraphCoordinate);
48
+ private _origin;
49
+ get origin(): MapGraphCoordinate;
50
+ set origin(value: MapGraphCoordinate);
51
+ private _bottomRight;
52
+ get bottomRight(): MapGraphCoordinate | undefined;
53
+ set bottomRight(value: MapGraphCoordinate | undefined);
54
+ /**
55
+ * The function creates a new vertex with the given id, value, latitude, and longitude.
56
+ * @param {VertexId} id - The id parameter is the unique identifier for the vertex. It is of type VertexId, which could
57
+ * be a string or a number depending on how you define it in your code.
58
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the `val` property of the vertex. It
59
+ * is of type `V['val']`, which means it should be of the same type as the `val` property of the vertex class `V`.
60
+ * @param {number} lat - The `lat` parameter represents the latitude of the vertex. It is a number that specifies the
61
+ * position of the vertex on the Earth's surface in the north-south direction.
62
+ * @param {number} long - The `long` parameter represents the longitude coordinate of the vertex.
63
+ * @returns The method is returning a new instance of the `MapVertex` class, casted as type `V`.
64
+ */
65
+ createVertex(id: VertexId, val?: V['val'], lat?: number, long?: number): V;
66
+ /**
67
+ * The function creates a new instance of a MapEdge with the given source, destination, weight, and value.
68
+ * @param {VertexId} src - The source vertex ID of the edge. It represents the starting point of the edge.
69
+ * @param {VertexId} dest - The `dest` parameter is the identifier of the destination vertex for the edge being
70
+ * created.
71
+ * @param {number} [weight] - The `weight` parameter is an optional number that represents the weight of the edge. It
72
+ * is used to assign a numerical value to the edge, which can be used in algorithms such as shortest path algorithms.
73
+ * If the weight is not provided, it can be set to a default value or left undefined.
74
+ * @param [val] - The `val` parameter is an optional value that can be assigned to the edge. It can be of any type,
75
+ * depending on the specific implementation of the `MapEdge` class.
76
+ * @returns a new instance of the `MapEdge` class, casted as type `E`.
77
+ */
78
+ createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E;
79
+ }