data-structure-typed 1.12.21 → 1.15.1

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 (48) hide show
  1. package/README.md +278 -179
  2. package/dist/data-structures/binary-tree/binary-tree.d.ts +46 -1
  3. package/dist/data-structures/binary-tree/binary-tree.js +67 -0
  4. package/dist/data-structures/binary-tree/segment-tree.d.ts +29 -0
  5. package/dist/data-structures/binary-tree/segment-tree.js +45 -0
  6. package/dist/data-structures/graph/abstract-graph.d.ts +40 -5
  7. package/dist/data-structures/graph/abstract-graph.js +47 -7
  8. package/dist/data-structures/graph/directed-graph.d.ts +8 -0
  9. package/dist/data-structures/graph/directed-graph.js +14 -2
  10. package/dist/data-structures/graph/undirected-graph.d.ts +10 -0
  11. package/dist/data-structures/graph/undirected-graph.js +23 -1
  12. package/dist/data-structures/hash/coordinate-map.d.ts +7 -1
  13. package/dist/data-structures/hash/coordinate-map.js +16 -0
  14. package/dist/data-structures/hash/coordinate-set.d.ts +7 -1
  15. package/dist/data-structures/hash/coordinate-set.js +16 -0
  16. package/dist/data-structures/heap/heap.d.ts +16 -0
  17. package/dist/data-structures/heap/heap.js +38 -0
  18. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +30 -7
  19. package/dist/data-structures/linked-list/doubly-linked-list.js +71 -4
  20. package/dist/data-structures/linked-list/singly-linked-list.d.ts +262 -328
  21. package/dist/data-structures/linked-list/singly-linked-list.js +258 -273
  22. package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -1
  23. package/dist/data-structures/priority-queue/priority-queue.js +18 -2
  24. package/dist/data-structures/queue/deque.d.ts +18 -7
  25. package/dist/data-structures/queue/deque.js +50 -3
  26. package/dist/data-structures/types/abstract-graph.d.ts +2 -2
  27. package/dist/utils/types/utils.d.ts +0 -49
  28. package/dist/utils/types/utils.js +14 -52
  29. package/dist/utils/utils.d.ts +1 -97
  30. package/dist/utils/utils.js +197 -546
  31. package/package.json +4 -3
  32. package/src/data-structures/binary-tree/aa-tree.ts +1 -1
  33. package/src/data-structures/binary-tree/binary-tree.ts +84 -14
  34. package/src/data-structures/binary-tree/segment-tree.ts +45 -13
  35. package/src/data-structures/graph/abstract-graph.ts +58 -15
  36. package/src/data-structures/graph/directed-graph.ts +14 -5
  37. package/src/data-structures/graph/undirected-graph.ts +23 -6
  38. package/src/data-structures/hash/coordinate-map.ts +13 -1
  39. package/src/data-structures/hash/coordinate-set.ts +13 -1
  40. package/src/data-structures/heap/heap.ts +31 -0
  41. package/src/data-structures/linked-list/doubly-linked-list.ts +68 -11
  42. package/src/data-structures/linked-list/singly-linked-list.ts +312 -334
  43. package/src/data-structures/priority-queue/priority-queue.ts +15 -2
  44. package/src/data-structures/queue/deque.ts +38 -8
  45. package/src/data-structures/types/abstract-graph.ts +3 -3
  46. package/src/utils/types/utils.ts +165 -167
  47. package/src/utils/utils.ts +209 -480
  48. package/tests/unit/data-structures/graph/directed-graph.test.ts +431 -8
@@ -73,6 +73,12 @@ var BinaryTreeNode = /** @class */ (function () {
73
73
  enumerable: false,
74
74
  configurable: true
75
75
  });
76
+ /**
77
+ * 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.
78
+ */
79
+ BinaryTreeNode.prototype.getId = function () {
80
+ return this._id;
81
+ };
76
82
  Object.defineProperty(BinaryTreeNode.prototype, "val", {
77
83
  get: function () {
78
84
  return this._val;
@@ -83,6 +89,12 @@ var BinaryTreeNode = /** @class */ (function () {
83
89
  enumerable: false,
84
90
  configurable: true
85
91
  });
92
+ /**
93
+ * 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.
94
+ */
95
+ BinaryTreeNode.prototype.getVal = function () {
96
+ return this._val;
97
+ };
86
98
  Object.defineProperty(BinaryTreeNode.prototype, "left", {
87
99
  get: function () {
88
100
  return this._left;
@@ -97,6 +109,12 @@ var BinaryTreeNode = /** @class */ (function () {
97
109
  enumerable: false,
98
110
  configurable: true
99
111
  });
112
+ /**
113
+ * 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.
114
+ */
115
+ BinaryTreeNode.prototype.getLeft = function () {
116
+ return this._left;
117
+ };
100
118
  Object.defineProperty(BinaryTreeNode.prototype, "right", {
101
119
  get: function () {
102
120
  return this._right;
@@ -111,6 +129,12 @@ var BinaryTreeNode = /** @class */ (function () {
111
129
  enumerable: false,
112
130
  configurable: true
113
131
  });
132
+ /**
133
+ * 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.
134
+ */
135
+ BinaryTreeNode.prototype.getRight = function () {
136
+ return this._right;
137
+ };
114
138
  Object.defineProperty(BinaryTreeNode.prototype, "parent", {
115
139
  get: function () {
116
140
  return this._parent;
@@ -121,6 +145,12 @@ var BinaryTreeNode = /** @class */ (function () {
121
145
  enumerable: false,
122
146
  configurable: true
123
147
  });
148
+ /**
149
+ * 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.
150
+ */
151
+ BinaryTreeNode.prototype.getParent = function () {
152
+ return this._parent;
153
+ };
124
154
  Object.defineProperty(BinaryTreeNode.prototype, "familyPosition", {
125
155
  get: function () {
126
156
  return this._familyPosition;
@@ -131,6 +161,12 @@ var BinaryTreeNode = /** @class */ (function () {
131
161
  enumerable: false,
132
162
  configurable: true
133
163
  });
164
+ /**
165
+ * 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.
166
+ */
167
+ BinaryTreeNode.prototype.getFamilyPosition = function () {
168
+ return this._familyPosition;
169
+ };
134
170
  Object.defineProperty(BinaryTreeNode.prototype, "count", {
135
171
  get: function () {
136
172
  return this._count;
@@ -141,6 +177,12 @@ var BinaryTreeNode = /** @class */ (function () {
141
177
  enumerable: false,
142
178
  configurable: true
143
179
  });
180
+ /**
181
+ * 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.
182
+ */
183
+ BinaryTreeNode.prototype.getCount = function () {
184
+ return this._count;
185
+ };
144
186
  Object.defineProperty(BinaryTreeNode.prototype, "height", {
145
187
  get: function () {
146
188
  return this._height;
@@ -151,6 +193,12 @@ var BinaryTreeNode = /** @class */ (function () {
151
193
  enumerable: false,
152
194
  configurable: true
153
195
  });
196
+ /**
197
+ * 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.
198
+ */
199
+ BinaryTreeNode.prototype.getHeight = function () {
200
+ return this._height;
201
+ };
154
202
  BinaryTreeNode.prototype.swapLocation = function (swapNode) {
155
203
  var val = swapNode.val, count = swapNode.count, height = swapNode.height;
156
204
  var tempNode = new BinaryTreeNode(swapNode.id, val);
@@ -213,6 +261,13 @@ var BinaryTree = /** @class */ (function () {
213
261
  enumerable: false,
214
262
  configurable: true
215
263
  });
264
+ /**
265
+ * 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 Getters (using the same name as the property) while utilizing separate method names for Setters.
266
+ * @returns The method is returning either a BinaryTreeNode object of type T or null.
267
+ */
268
+ BinaryTree.prototype.getRoot = function () {
269
+ return this._root;
270
+ };
216
271
  Object.defineProperty(BinaryTree.prototype, "size", {
217
272
  get: function () {
218
273
  return this._size;
@@ -223,6 +278,12 @@ var BinaryTree = /** @class */ (function () {
223
278
  enumerable: false,
224
279
  configurable: true
225
280
  });
281
+ /**
282
+ * 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.
283
+ */
284
+ BinaryTree.prototype.getSize = function () {
285
+ return this._size;
286
+ };
226
287
  Object.defineProperty(BinaryTree.prototype, "count", {
227
288
  get: function () {
228
289
  return this._count;
@@ -233,6 +294,12 @@ var BinaryTree = /** @class */ (function () {
233
294
  enumerable: false,
234
295
  configurable: true
235
296
  });
297
+ /**
298
+ * 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.
299
+ */
300
+ BinaryTree.prototype.getCount = function () {
301
+ return this._count;
302
+ };
236
303
  /**
237
304
  * The function creates a new binary tree node with the given id, value, and count, or returns null if the value is
238
305
  * null.
@@ -10,21 +10,45 @@ export declare class SegmentTreeNode {
10
10
  constructor(start: number, end: number, sum: number, val?: SegmentTreeNodeVal | null);
11
11
  protected _start: number;
12
12
  get start(): number;
13
+ /**
14
+ * 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.
15
+ */
16
+ getStart(): number;
13
17
  set start(v: number);
14
18
  protected _end: number;
15
19
  get end(): number;
20
+ /**
21
+ * 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.
22
+ */
23
+ getEnd(): number;
16
24
  set end(v: number);
17
25
  protected _val: SegmentTreeNodeVal | null;
18
26
  get val(): SegmentTreeNodeVal | null;
27
+ /**
28
+ * 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.
29
+ */
30
+ getVal(): SegmentTreeNodeVal | null;
19
31
  set val(v: SegmentTreeNodeVal | null);
20
32
  protected _sum: number;
21
33
  get sum(): number;
34
+ /**
35
+ * 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.
36
+ */
37
+ getSum(): number;
22
38
  set sum(v: number);
23
39
  protected _left: SegmentTreeNode | null;
24
40
  get left(): SegmentTreeNode | null;
41
+ /**
42
+ * 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.
43
+ */
44
+ getLeft(): SegmentTreeNode | null;
25
45
  set left(v: SegmentTreeNode | null);
26
46
  protected _right: SegmentTreeNode | null;
27
47
  get right(): SegmentTreeNode | null;
48
+ /**
49
+ * 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.
50
+ */
51
+ getRight(): SegmentTreeNode | null;
28
52
  set right(v: SegmentTreeNode | null);
29
53
  }
30
54
  export declare class SegmentTree {
@@ -43,6 +67,11 @@ export declare class SegmentTree {
43
67
  constructor(values: number[], start?: number, end?: number);
44
68
  protected _root: SegmentTreeNode | null;
45
69
  get root(): SegmentTreeNode | null;
70
+ /**
71
+ * 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.
72
+ */
73
+ getRoot(): SegmentTreeNode | null;
74
+ set root(v: SegmentTreeNode | null);
46
75
  /**
47
76
  * The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
48
77
  * for each segment.
@@ -31,6 +31,12 @@ var SegmentTreeNode = /** @class */ (function () {
31
31
  enumerable: false,
32
32
  configurable: true
33
33
  });
34
+ /**
35
+ * 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.
36
+ */
37
+ SegmentTreeNode.prototype.getStart = function () {
38
+ return this._start;
39
+ };
34
40
  Object.defineProperty(SegmentTreeNode.prototype, "end", {
35
41
  get: function () {
36
42
  return this._end;
@@ -41,6 +47,12 @@ var SegmentTreeNode = /** @class */ (function () {
41
47
  enumerable: false,
42
48
  configurable: true
43
49
  });
50
+ /**
51
+ * 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.
52
+ */
53
+ SegmentTreeNode.prototype.getEnd = function () {
54
+ return this._end;
55
+ };
44
56
  Object.defineProperty(SegmentTreeNode.prototype, "val", {
45
57
  get: function () {
46
58
  return this._val;
@@ -51,6 +63,12 @@ var SegmentTreeNode = /** @class */ (function () {
51
63
  enumerable: false,
52
64
  configurable: true
53
65
  });
66
+ /**
67
+ * 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.
68
+ */
69
+ SegmentTreeNode.prototype.getVal = function () {
70
+ return this._val;
71
+ };
54
72
  Object.defineProperty(SegmentTreeNode.prototype, "sum", {
55
73
  get: function () {
56
74
  return this._sum;
@@ -61,6 +79,12 @@ var SegmentTreeNode = /** @class */ (function () {
61
79
  enumerable: false,
62
80
  configurable: true
63
81
  });
82
+ /**
83
+ * 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.
84
+ */
85
+ SegmentTreeNode.prototype.getSum = function () {
86
+ return this._sum;
87
+ };
64
88
  Object.defineProperty(SegmentTreeNode.prototype, "left", {
65
89
  get: function () {
66
90
  return this._left;
@@ -71,6 +95,12 @@ var SegmentTreeNode = /** @class */ (function () {
71
95
  enumerable: false,
72
96
  configurable: true
73
97
  });
98
+ /**
99
+ * 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.
100
+ */
101
+ SegmentTreeNode.prototype.getLeft = function () {
102
+ return this._left;
103
+ };
74
104
  Object.defineProperty(SegmentTreeNode.prototype, "right", {
75
105
  get: function () {
76
106
  return this._right;
@@ -81,6 +111,12 @@ var SegmentTreeNode = /** @class */ (function () {
81
111
  enumerable: false,
82
112
  configurable: true
83
113
  });
114
+ /**
115
+ * 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.
116
+ */
117
+ SegmentTreeNode.prototype.getRight = function () {
118
+ return this._right;
119
+ };
84
120
  return SegmentTreeNode;
85
121
  }());
86
122
  exports.SegmentTreeNode = SegmentTreeNode;
@@ -108,9 +144,18 @@ var SegmentTree = /** @class */ (function () {
108
144
  get: function () {
109
145
  return this._root;
110
146
  },
147
+ set: function (v) {
148
+ this._root = v;
149
+ },
111
150
  enumerable: false,
112
151
  configurable: true
113
152
  });
153
+ /**
154
+ * 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.
155
+ */
156
+ SegmentTree.prototype.getRoot = function () {
157
+ return this._root;
158
+ };
114
159
  /**
115
160
  * The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
116
161
  * for each segment.
@@ -1,9 +1,13 @@
1
1
  import type { DijkstraResult, IGraph, VertexId } from '../types';
2
2
  export declare class AbstractVertex {
3
- constructor(id: VertexId);
4
3
  protected _id: VertexId;
5
4
  get id(): VertexId;
5
+ /**
6
+ * 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.
7
+ */
8
+ getId(): VertexId;
6
9
  set id(v: VertexId);
10
+ constructor(id: VertexId);
7
11
  }
8
12
  export declare abstract class AbstractEdge {
9
13
  static DEFAULT_EDGE_WEIGHT: number;
@@ -15,9 +19,17 @@ export declare abstract class AbstractEdge {
15
19
  protected constructor(weight?: number);
16
20
  private _weight;
17
21
  get weight(): number;
22
+ /**
23
+ * 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.
24
+ */
25
+ getWeight(): number;
18
26
  set weight(v: number);
19
27
  private _hashCode;
20
28
  get hashCode(): string;
29
+ /**
30
+ * 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.
31
+ */
32
+ getHashCode(): string;
21
33
  set hashCode(v: string);
22
34
  }
23
35
  export declare abstract class AbstractGraph<V extends AbstractVertex, E extends AbstractEdge> implements IGraph<V, E> {
@@ -44,9 +56,9 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
44
56
  * The function checks if a vertex exists in a graph.
45
57
  * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
46
58
  * (`VertexId`).
47
- * @returns The method `containsVertex` returns a boolean value.
59
+ * @returns The method `hasVertex` returns a boolean value.
48
60
  */
49
- containsVertex(vertexOrId: V | VertexId): boolean;
61
+ hasVertex(vertexOrId: V | VertexId): boolean;
50
62
  /**
51
63
  * The function `vertexSet()` returns a map of vertices.
52
64
  * @returns The method `vertexSet()` returns a map of vertex IDs to vertex objects.
@@ -84,10 +96,10 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
84
96
  * a vertex in a graph, while V represents the type of the vertex itself.
85
97
  * @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in an edge. It can be either a `VertexId`
86
98
  * or a `V` type.
87
- * @returns The function `containsEdge` returns a boolean value. It returns `true` if there is an edge between the
99
+ * @returns The function `hasEdge` returns a boolean value. It returns `true` if there is an edge between the
88
100
  * vertices `v1` and `v2`, and `false` otherwise.
89
101
  */
90
- containsEdge(v1: VertexId | V, v2: VertexId | V): boolean;
102
+ hasEdge(v1: VertexId | V, v2: VertexId | V): boolean;
91
103
  abstract addEdge(edge: E): boolean;
92
104
  /**
93
105
  * The function sets the weight of an edge between two vertices in a graph.
@@ -164,8 +176,18 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
164
176
  * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult<V>`.
165
177
  */
166
178
  dijkstraWithoutHeap(src: V | VertexId, dest?: V | VertexId | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult<V>;
179
+ /**
180
+ * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
181
+ * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
182
+ * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
183
+ */
184
+ /**
185
+ * Dijkstra algorithm time: O(logVE) space: O(V + E)
186
+ * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
187
+ */
167
188
  /**
168
189
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
190
+ * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
169
191
  * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
170
192
  * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
171
193
  * @param {V | VertexId} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
@@ -186,6 +208,13 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
186
208
  /**
187
209
  * BellmanFord time:O(VE) space:O(V)
188
210
  * one to rest pairs
211
+ * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
212
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
213
+ */
214
+ /**
215
+ * BellmanFord time:O(VE) space:O(V)
216
+ * one to rest pairs
217
+ * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
189
218
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
190
219
  * all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
191
220
  * @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
@@ -209,6 +238,12 @@ export declare abstract class AbstractGraph<V extends AbstractVertex, E extends
209
238
  /**
210
239
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
211
240
  * all pairs
241
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
242
+ */
243
+ /**
244
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
245
+ * all pairs
246
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
212
247
  * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
213
248
  * graph.
214
249
  * @returns The function `floyd()` returns an object with two properties: `costs` and `predecessor`. The `costs`
@@ -60,6 +60,12 @@ var AbstractVertex = /** @class */ (function () {
60
60
  enumerable: false,
61
61
  configurable: true
62
62
  });
63
+ /**
64
+ * 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.
65
+ */
66
+ AbstractVertex.prototype.getId = function () {
67
+ return this._id;
68
+ };
63
69
  return AbstractVertex;
64
70
  }());
65
71
  exports.AbstractVertex = AbstractVertex;
@@ -85,6 +91,12 @@ var AbstractEdge = /** @class */ (function () {
85
91
  enumerable: false,
86
92
  configurable: true
87
93
  });
94
+ /**
95
+ * 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.
96
+ */
97
+ AbstractEdge.prototype.getWeight = function () {
98
+ return this._weight;
99
+ };
88
100
  Object.defineProperty(AbstractEdge.prototype, "hashCode", {
89
101
  get: function () {
90
102
  return this._hashCode;
@@ -95,6 +107,12 @@ var AbstractEdge = /** @class */ (function () {
95
107
  enumerable: false,
96
108
  configurable: true
97
109
  });
110
+ /**
111
+ * 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.
112
+ */
113
+ AbstractEdge.prototype.getHashCode = function () {
114
+ return this._hashCode;
115
+ };
98
116
  AbstractEdge.DEFAULT_EDGE_WEIGHT = 1;
99
117
  return AbstractEdge;
100
118
  }());
@@ -103,8 +121,7 @@ exports.AbstractEdge = AbstractEdge;
103
121
  var AbstractGraph = /** @class */ (function () {
104
122
  function AbstractGraph() {
105
123
  this._vertices = new Map();
106
- // unionFind() {
107
- // }
124
+ // unionFind() {}
108
125
  /**--- end find cycles --- */
109
126
  // Minimum Spanning Tree
110
127
  }
@@ -133,9 +150,9 @@ var AbstractGraph = /** @class */ (function () {
133
150
  * The function checks if a vertex exists in a graph.
134
151
  * @param {V | VertexId} vertexOrId - The parameter `vertexOrId` can accept either a vertex object (`V`) or a vertex ID
135
152
  * (`VertexId`).
136
- * @returns The method `containsVertex` returns a boolean value.
153
+ * @returns The method `hasVertex` returns a boolean value.
137
154
  */
138
- AbstractGraph.prototype.containsVertex = function (vertexOrId) {
155
+ AbstractGraph.prototype.hasVertex = function (vertexOrId) {
139
156
  return this._vertices.has(this.getVertexId(vertexOrId));
140
157
  };
141
158
  /**
@@ -152,7 +169,7 @@ var AbstractGraph = /** @class */ (function () {
152
169
  * false. Otherwise, it will add the newVertex to the graph and return true.
153
170
  */
154
171
  AbstractGraph.prototype.addVertex = function (newVertex) {
155
- if (this.containsVertex(newVertex)) {
172
+ if (this.hasVertex(newVertex)) {
156
173
  return false;
157
174
  }
158
175
  this._vertices.set(newVertex.id, newVertex);
@@ -199,10 +216,10 @@ var AbstractGraph = /** @class */ (function () {
199
216
  * a vertex in a graph, while V represents the type of the vertex itself.
200
217
  * @param {VertexId | V} v2 - The parameter `v2` represents the second vertex in an edge. It can be either a `VertexId`
201
218
  * or a `V` type.
202
- * @returns The function `containsEdge` returns a boolean value. It returns `true` if there is an edge between the
219
+ * @returns The function `hasEdge` returns a boolean value. It returns `true` if there is an edge between the
203
220
  * vertices `v1` and `v2`, and `false` otherwise.
204
221
  */
205
- AbstractGraph.prototype.containsEdge = function (v1, v2) {
222
+ AbstractGraph.prototype.hasEdge = function (v1, v2) {
206
223
  var edge = this.getEdge(v1, v2);
207
224
  return !!edge;
208
225
  };
@@ -613,8 +630,18 @@ var AbstractGraph = /** @class */ (function () {
613
630
  genPaths && getPaths(minDest);
614
631
  return { distMap: distMap, preMap: preMap, seen: seen, paths: paths, minDist: minDist, minPath: minPath };
615
632
  };
633
+ /**
634
+ * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
635
+ * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edges.
636
+ * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(V^3), where V is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
637
+ */
616
638
  /**
617
639
  * Dijkstra algorithm time: O(logVE) space: O(V + E)
640
+ * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
641
+ */
642
+ /**
643
+ * Dijkstra algorithm time: O(logVE) space: O(V + E)
644
+ * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
618
645
  * The `dijkstra` function implements Dijkstra's algorithm to find the shortest path between a source vertex and an
619
646
  * optional destination vertex, and optionally returns the minimum distance, the paths, and other information.
620
647
  * @param {V | VertexId} src - The `src` parameter represents the source vertex from which the Dijkstra algorithm will
@@ -763,6 +790,13 @@ var AbstractGraph = /** @class */ (function () {
763
790
  /**
764
791
  * BellmanFord time:O(VE) space:O(V)
765
792
  * one to rest pairs
793
+ * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
794
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
795
+ */
796
+ /**
797
+ * BellmanFord time:O(VE) space:O(V)
798
+ * one to rest pairs
799
+ * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edges for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edges, the Bellman-Ford algorithm is more flexible in some scenarios.
766
800
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
767
801
  * all other vertices in a graph, and optionally detects negative cycles and generates the minimum path.
768
802
  * @param {V | VertexId} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
@@ -874,6 +908,12 @@ var AbstractGraph = /** @class */ (function () {
874
908
  /**
875
909
  * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
876
910
  * all pairs
911
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
912
+ */
913
+ /**
914
+ * Floyd algorithm time: O(V^3) space: O(V^2), not support graph with negative weight cycle
915
+ * all pairs
916
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edges, and it can simultaneously compute shortest paths between any two nodes.
877
917
  * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertices in a
878
918
  * graph.
879
919
  * @returns The function `floyd()` returns an object with two properties: `costs` and `predecessor`. The `costs`
@@ -21,9 +21,17 @@ export declare class DirectedEdge extends AbstractEdge {
21
21
  constructor(src: VertexId, dest: VertexId, weight?: number);
22
22
  private _src;
23
23
  get src(): 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
+ getSrc(): VertexId;
24
28
  set src(v: VertexId);
25
29
  private _dest;
26
30
  get dest(): VertexId;
31
+ /**
32
+ * 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.
33
+ */
34
+ getDest(): VertexId;
27
35
  set dest(v: VertexId);
28
36
  }
29
37
  export declare class DirectedGraph<V extends DirectedVertex, E extends DirectedEdge> extends AbstractGraph<V, E> implements IDirectedGraph<V, E> {
@@ -101,6 +101,12 @@ var DirectedEdge = /** @class */ (function (_super) {
101
101
  enumerable: false,
102
102
  configurable: true
103
103
  });
104
+ /**
105
+ * 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.
106
+ */
107
+ DirectedEdge.prototype.getSrc = function () {
108
+ return this._src;
109
+ };
104
110
  Object.defineProperty(DirectedEdge.prototype, "dest", {
105
111
  get: function () {
106
112
  return this._dest;
@@ -111,6 +117,12 @@ var DirectedEdge = /** @class */ (function (_super) {
111
117
  enumerable: false,
112
118
  configurable: true
113
119
  });
120
+ /**
121
+ * 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.
122
+ */
123
+ DirectedEdge.prototype.getDest = function () {
124
+ return this._dest;
125
+ };
114
126
  return DirectedEdge;
115
127
  }(abstract_graph_1.AbstractEdge));
116
128
  exports.DirectedEdge = DirectedEdge;
@@ -153,7 +165,7 @@ var DirectedGraph = /** @class */ (function (_super) {
153
165
  * graph, and `false` if either the source or destination vertices of the edge are not present in the graph.
154
166
  */
155
167
  DirectedGraph.prototype.addEdge = function (edge) {
156
- if (!(this.containsVertex(edge.src) && this.containsVertex(edge.dest))) {
168
+ if (!(this.hasVertex(edge.src) && this.hasVertex(edge.dest))) {
157
169
  return false;
158
170
  }
159
171
  var srcVertex = this.getVertex(edge.src);
@@ -482,7 +494,7 @@ var DirectedGraph = /** @class */ (function (_super) {
482
494
  * returns null.
483
495
  */
484
496
  DirectedGraph.prototype.getEndsOfEdge = function (edge) {
485
- if (!this.containsEdge(edge.src, edge.dest)) {
497
+ if (!this.hasEdge(edge.src, edge.dest)) {
486
498
  return null;
487
499
  }
488
500
  var v1 = this.getVertex(edge.src);
@@ -20,10 +20,20 @@ export declare class UndirectedEdge extends AbstractEdge {
20
20
  constructor(v1: VertexId, v2: VertexId, weight?: number);
21
21
  private _vertices;
22
22
  get vertices(): [VertexId, VertexId];
23
+ /**
24
+ * 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.
25
+ */
26
+ getVertices(): [VertexId, VertexId];
23
27
  set vertices(v: [VertexId, VertexId]);
24
28
  }
25
29
  export declare class UndirectedGraph<V extends UndirectedVertex, E extends UndirectedEdge> extends AbstractGraph<V, E> {
26
30
  protected _edges: Map<V, E[]>;
31
+ get edges(): Map<V, E[]>;
32
+ /**
33
+ * 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.
34
+ */
35
+ getEdges(): Map<V, E[]>;
36
+ protected set edges(v: Map<V, E[]>);
27
37
  constructor();
28
38
  /**
29
39
  * The function `getEdge` returns the first edge that connects two vertices, or null if no such edge exists.